I need to change the tab when button is pressed, and the tab should be identified by id. The following code doesn't work for me - just the page is reloaded:
<div class="form-actions">
<button class="btn btn-primary" id="btn-next">Next</button>
<button type="reset" class="btn">Clear</button>
</div>
...
<div class="tab-pane active" id="2">
...
$("#btn-next").click(function(event) {
$('#2').tab('show');
});
You can use something like this:
function nextTab(elem) {
$(elem + ' li.active')
.next()
.find('a[data-toggle="tab"]')
.click();
}
function prevTab(elem) {
$(elem + ' li.active')
.prev()
.find('a[data-toggle="tab"]')
.click();
}
and use nextTab('#tab');
or prevTab('#tab');
Live example with continue actions: http://jsbin.com/atinel/9/edit#javascript,html
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