How to active tab using javascript?
Home
About Us
Contact Us
<li class="active" id="home" onclick="opentab(event, 'home')"> <a href="#tab_1_1" data-toggle="tab"> <i class="fa fa-info-circle"></i> <span class="caption-subject font-dark sbold uppercase"> Home</span> </a> </li>
<li id="aboutus" onclick="opentab(event, 'aboutus')"> <a href="#tab_1_2" data-toggle="tab"> <i class="fa fa-info-circle"></i> <span class="caption-subject font-dark sbold uppercase">About Us</span> </a> </li>
<li id="contactus" onclick="opentab(event, 'contactus')"> <a href="#tab_1_3" data-toggle="tab"> <i class="fa fa-info-circle"></i> <span class="caption-subject font-dark sbold uppercase">Contact Us</span> </a> </li>
<script>
function opentab(evt, tabName) {
if(tabName == "Home")
{
document.getElementById('home').className = 'active';
document.getElementById('aboutus').className = '';
document.getElementById('contactus').className = '';
}
else if(tabName == "aboutus")
{
document.getElementById('home').className = '';
document.getElementById('aboutus').className = 'active';
document.getElementById('contactus').className = '';
}
else if(tabName == "contactus")
{
document.getElementById('home').className = '';
document.getElementById('aboutus').className = '';
document.getElementById('contactus').className = 'active';
}
}
</script>
Previous
Next