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: /
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.
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/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.
Share Improve this question edited Mar 18, 2015 at 21:55 amphetamachine 30.6k12 gold badges67 silver badges74 bronze badges asked Jan 8, 2015 at 15:31 ntalektntalekt 8521 gold badge12 silver badges35 bronze badges4 Answers
Reset to default 9From 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/sesu6rkn/1/
I've encountered this before and if I recall I had to remove the class="active" from both tab and tabContent.
This might help: https://stackoverflow./a/11762931/1214858
i used this works fine i guess
$('.nav-tabs > li:first-child > a')[0].click();
The accepted answer didn't work for me, so I found this as solution for the problem. I just trigger a click event on the first link:
$('.nav-tabs a:first').click();