So I have two nav tab on the top of my page to switch between two views:
<ul class="nav nav-tabs">
<li class="active"><a data-target="#first-tab" data-toggle="tab">FOO tab</a></li>
<li><a data-target="#second-tab" data-toggle="tab">BAR Tab</a></li>
</ul>
<div class="tab-pane fade in active" id="first-tab"> [...] </div>
<div class="tab-pane fade in active" id="second-tab"> [...] </div>
Is there a way to toggle between the two pane other than using the tabs? So say I have a button in the first-tab div, when clicked, it will switch to the second-tab div. I want to take away the tabs complete, and use another way to trigger the switch between to pane, e.g. in an onclick function
<div class="tab-content">
<div class="tab-pane fade in active" id="first-tab">
<a data-target="#second-tab" data-toggle="tab">BAR Tab</a>
</div>
<div class="tab-pane fade" id="second-tab">
<a data-target="#first-tab" data-toggle="tab">FOO tab</a>
</div>
</div>
Of course you can, but you made 2 mistakes:
in active classes.tab-content around tab divs.JS version:
('[data-target=#first-tab]').click(function (e) {
e.preventDefault();
$(this).tab('show');
});
$('[data-target=#second-tab]').click(function (e) {
e.preventDefault();
$(this).tab('show');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With