Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the active bootstrap tab on button click

I want to change the active bootstrap tab on the click of another button.

I have tried add id's to the tabs li and write custom jquery code.

$('#emailNotify').click(function () {
    $('#notify').addClass('active').attr('aria-expanded','true');
    $('#myacc').removeClass('active').attr('aria-expanded','false');
});

This code works fine on first click but it doesn't change back when I tried to click My Account tab again.

Image of Tabs and Button

Markup:

<ul class="content-list museo_sans500">
<li><a href="javascript:void(0)">Change Password</a></li>
<li><a id="emailNotify" data-toggle="tab">Change Email Notifications</a></li>
<li><a href="javascript:void(0)">Change Profile Picture</a></li>
</ul>
like image 778
Farjad Hasan Avatar asked Sep 01 '15 19:09

Farjad Hasan


2 Answers

You can change the active tab on the click event button with that:

$('#changetabbutton').click(function(e){
    e.preventDefault();
    $('#mytabs a[href="#second"]').tab('show');
})

Here's a JSFiddle with an example:

http://jsfiddle.net/4ns0mdcf/

like image 124
Carlos Mayo Avatar answered Oct 09 '22 16:10

Carlos Mayo


You should use twitter-boostrap way to change between tabs:

$('#myTab a:first').tab('show'); // Select first tab
$('#myTab a:last').tab('show'); // Select last tab

or

$('#notify').tab('show'); // show notification tab
like image 22
Assem Avatar answered Oct 09 '22 14:10

Assem