JSFiddle - React, Tailwind, and code Playground

by kayenglajom

HTML

<div class="button" onclick="switch_div(1);">
  1
</div>
<div class="button" onclick="switch_div(2);">
  2
</div>

<div class="content hide" id="show_1">
  Show by default (and when button 1 is clicked)
</div>
<div class="content hide" id="show_2">
  Show this div when button 2 is clicked
</div>

CSS

.button {
  width: 100px;
  height: 30px;
  display: inline-block;
  background-color: black;
  margin: 0 10px 10px 0;
  color: #fff;
  text-align: center;
  line-height: 30px;
  cursor: pointer;
}

.button:hover {
  background-color: red;
}

.content {
  width: 400px;
  height: 100px;
  display: block;
  background-color: gray;
}

.hide {
  display: none;
}

JavaScript

function switch_div(show) {  
  document.getElementById("show_"+show).style.display = "block";
  document.getElementById("show_"+((show==1)?2:1)).style.display = "none";
}