DEV Community

Umapreethi Santhanakrishnan
Umapreethi Santhanakrishnan

Posted on

Creating Tabs using Html,css,js

Fourth day of 100 days of code.

HTML Code:

 <div class="tabs">
      <button id="tab1" onclick="open(event, 'html')" type="button">
        HTML
      </button>
      <button id="tab2" onclick="open(event, 'css')" type="button">
        CSS
      </button>
      <button id="tab3" onclick="open(event, 'js')" type="button">
        JS
      </button>
    </div>
    <div id="cont"></div>
Enter fullscreen mode Exit fullscreen mode

Index.js

function open(event, skill) {
  event.preventDefault();

  const content = document.getElementById("cont");
  content.classList.add("content");
  if (skill == "html") {
    content.innerHTML =
      "HTML is the standard markup language for Web pages.With HTML you can create your own Website.";
  }
  if (skill == "css") {
    content.innerHTML =
      "CSS is the language we use to style an HTML document.CSS describes how HTML elements should be displayed.";
  }
  if (skill == "js") {
    content.innerHTML =
      "JavaScript is the worlds most popular programming language.JavaScript is the programming language of the Web.";
  }
}
Enter fullscreen mode Exit fullscreen mode

Through onclick event, pass the skill and if the skill matches the button value, update your innerHTML.

Top comments (0)