I'm teaching myself jQuery and made myself a tabbed container with Bootstrap.
I'm using a button group as the tabs for my 'container' (really just 4 panels) and to set one of the buttons as toggled on I need to use the data-toggle="button" attribute, but I'm unable to remove the attribute or give it to a new button when that one is made active. Currently the button that is initially set to toggled stays that way. I have no errors in my console.
Here is my HTML:
<div class="panel-set">
<div class="tabs btn-group" role="group" aria-label="...">
<button rel="panel1" type="button" class="tab-btn active btn btn-default" data-toggle="button">Tab 1</button>
<button rel="panel2" type="button" class="tab-btn btn btn-default" data-toggle="">Tab 2</button>
<button rel="panel3" type="button" class="tab-btn btn btn-default" data-toggle="">Tab 3</button>
<button rel="panel4" type="button" class="tab-btn btn btn-default" data-toggle="">Tab 4</button>
</div>
<div id="panel1" class="panel active panel-primary">
...
...
</div>
Here is my javascript:
$(function() {
$('.panel-set .tabs .tab-btn').on('click', function(){
//Remove toggle and add to newly active button
$('.panel-set .tabs .tab-btn.active').removeAttr('data-toggle');
$('this').attr('data-toggle', 'button');
//Figure out panel to show
var panelToShow = $(this).attr('rel');
//Hide current panel
$('.panel-set .panel.active').hide( function(){
$(this).removeClass('active');
$('#'+panelToShow).show( function(){
$(this).addClass('active');
});
});
});
});