JSFiddle - React, Tailwind, and code Playground

by Fabio Dan

HTML

<div class='parent'>
<div>
  <ul>
  <li id='tabA' class='tabButton' onClick='tabOneClick(this)'>Tab A</li>
  <li id='tabB' class='tabButton' onClick='tabTwoClick(this)'>Tab B</li>
  </ul>
</div>

<div id='tabOne' class='tabContent'>
  <p>Lorem Ipsum dolor</p>
 </div>
 
 <div id='tabTwo' class='hide'>
   <p>HTML/ CSS/Javascript</p>
 </div>
 </div>

<!--
Build a tab component using plain HTML/CSS/JavaScript.

In case you forget any API method, attribute name, etc, you can search on any reference website like MDN, etc. You are not allowed to search for the solution of the problem.

Try to use all the best practices you know about HTML, CSS and JavaScript to build this component.

Mockup:
https://i.imgur.com/Qk71XWl.jpg

Please make the component fully functional. The content can be static in the HTML.
-->

CSS

.hide{
  display: none;
}

#parent{
  width: 150px;
}

ul{
  display: flex;
  width: 150px;
  text-decoration: none;
}
li{
  text-decoration: none;
  border: 1px solid black;
  width: 150px;
  text-align: center;
  //display: inline-block;
}

#tabOne, #tabTwo{
  border: 1px solid black;
  height: 150px;
  width: 150px;
}

JavaScript

function tabOneClick() {
    var elem = document.getElementById('tabOne');
    var elemTwo = document.getElementById('tabTwo');
    
    elem.classList.remove('hide');
    elemTwo.classList.add('hide');
    
    
  }
  
  function tabTwoClick(){
    var elem = document.getElementById('tabOne');
    var elemTwo = document.getElementById('tabTwo');
    
    elem.classList.add('hide');
    elemTwo.classList.remove('hide');
  } 
  
 /*  function tabClicked(elem) {
    var tabClass=document.getElementsByClassName('tabContent');
    
    for(var i=0; i< tabClass.length; i++){
      tabClass[i].classList.add('hide');
    }
    var tabId = elem.id;
        //document.getElementById(tabId).classList.remove('hide')
        
        //if(tabId === 'tabA'){
          var elem = document.getElementById(tabId);
          elem.classList.remove('hide');
    //}
   
    
  } */