tab view in html code example
Example 1: javascript tabs example
const showHideAll =(list)=>{
for(var i = 0; i < list.length; i++){
list[i].classList.remove('show');
list[i].classList.add('hide'); // depending on what you're doing
}
}
window.onload = function() {
let innerDiv = document.getElementsByClassName("inner-description");
let clicked = document.querySelectorAll('.show-hide-description');
clicked.forEach((item, i) => {
let clickedId = item.id;
document.querySelector(`#${clickedId}`).addEventListener('click',()=>{
let clickedIdDescription = document.getElementById(`${clickedId}-description`);
if(clickedIdDescription.classList.contains('show')){
showHideAll(innerDiv)
} else {
showHideAll(innerDiv)
clickedIdDescription.classList.remove('hide');
clickedIdDescription.classList.add('show');
}
})
});
}
Example 2: tab view in html
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">Profile</a>
</li>
<li class="nav-item">
<a class="nav-link" id="contact-tab" data-toggle="tab" href="#contact" role="tab" aria-controls="contact" aria-selected="false">Contact</a>
</li>
</ul>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">...</div>
<div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">...</div>
<div class="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">...</div>