Using tabs within a tab doesn't seem to be working as expected using HTML and TailwindCss. What's going wrong?
const tabs = document.querySelectorAll(".tabs");
const tab = document.querySelectorAll(".tab");
const panel = document.querySelectorAll(".tab-content");
function onTabClick(event) {
// deactivate existing active tabs and panel
for (let i = 0; i < tab.length; i++) {
tab[i].classList.remove("active");
}
for (let i = 0; i < panel.length; i++) {
panel[i].classList.remove("active");
}
// activate new tabs and panel
event.target.classList.add('active');
let classString = event.target.getAttribute('data-target');
console.log(classString);
document.getElementById('panels').getElementsByClassName(classString)[0].classList.add("active");
}
for (let i = 0; i < tab.length; i++) {
tab[i].addEventListener('click', onTabClick, false);
}
.tab-content {
display: none;
}
.tab-content.active {
display: block;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/1.1.4/tailwind.min.css" rel="stylesheet" />
<div class="bg-white">
<nav class="tabs flex flex-col sm:flex-row">
<button data-target="panel-1" class="tab active text-gray-600 py-4 px-6 block hover:text-blue-500 focus:outline-none text-blue-500 border-b-2 font-medium border-blue-500">
Summary Reports
</button>
<button data-target="panel-2" class="tab ext-gray-600 py-4 px-6 block hover:text-blue-500 focus:outline-none">
Trend Reports
</button>
<button data-target="panel-3" class="tab text-gray-600 py-4 px-6 block hover:text-blue-500 focus:outline-none">
Predictive Reports
</button>
</nav>
</div>
<div id="panels">
<div class="panel-1 tab-content active py-5">
<div class="bg-white">
<nav class="tabs flex flex-col sm:flex-row">
<button data-target="panel-1" class="tab active text-gray-600 py-4 px-6 block hover:text-blue-500 focus:outline-none text-blue-500 border-b-2 font-medium border-blue-500">
Number of students submitted on a specific day
</button>
<button data-target="panel-2" class="tab ext-gray-600 py-4 px-6 block hover:text-blue-500 focus:outline-none">
Number of students that submitted for a specific module code
</button>
</nav>
</div>
<div id="panels">
<div class="panel-1 tab-content active py-5">
Number of students submitted on a specific day
</div>
<div class="panel-2 tab-content py-5">
Number of students that submitted for a specific module code
</div>
</div>
</div>
<div class="panel-2 tab-content py-5">
Trend Reports
</div>
<div class="panel-3 tab-content py-5">
Predictive Reports
</div>
</div>