Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 3 Default to first tab

I have a dynamic modal with two tabs. I want #tab1 to always be the default tab when someone opens the modal. The problem is if I open the modal and click on #tab2 then close, when I open the modal it is still on #tab2.

JSFiddle: http://jsfiddle.net/9zo9hka4/

I'm not sure how do it. I've tried setting the tab back to #tab1 when I see the .on('hidden.bs.modal' event but that doesn't seem to work.

Any help would be appreciated.

like image 824
solar411 Avatar asked Jan 08 '15 15:01

solar411


1 Answers

From the Bootstrap docs you can activate the first tab like this:

$('#myTab a:first').tab('show')

So just add that to your modal when it's closed like this:

$('#clusterprofileanomalies').on('hidden.bs.modal', function () {
    //Add this line:
    $('.nav-tabs a:first').tab('show');

    //Snipped other non-relevant code
});

Update of your fiddle: http://jsfiddle.net/sesu6rkn/1/

like image 53
DavidG Avatar answered Sep 30 '22 21:09

DavidG