bootstrap: class="active" managed improperly with data-toggle="tab"
This works:
<div class=navbar navbar-light bg-faded>
<ul class=nav navbar-nav>
<a class=nav-item nav-link active data-toggle=tab href=#start>Start</a>
<a class=nav-item nav-link data-toggle=tab href=#form>Form</a>
<a class=nav-item nav-link data-toggle=tab href=#status>Status</a>
<a class=nav-item nav-link data-toggle=tab href=#reports>Reports</a>
</ul>
</div>
<div class=tab-content>
<div class=tab-pane active id=start>1</div>
<div class=tab-pane id=form>2</div>
<div class=tab-pane id=status>3</div>
<div class=tab-pane id=reports>4</div>
</div>
However when the <ul> is changed to a <div>, the active classes are never unset, thus breaking the data-toggle.
This does not work:
<div class=navbar navbar-light bg-faded>
<div class=nav navbar-nav>
<a class=nav-item nav-link active data-toggle=tab href=#start>Start</a>
<a class=nav-item nav-link data-toggle=tab href=#form>Form</a>
<a class=nav-item nav-link data-toggle=tab href=#status>Status</a>
<a class=nav-item nav-link data-toggle=tab href=#reports>Reports</a>
</div>
</div>
<div class=tab-content>
<div class=tab-pane active id=start>1</div>
<div class=tab-pane id=form>2</div>
<div class=tab-pane id=status>3</div>
<div class=tab-pane id=reports>4</div>
</div>
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 4
- Comments: 34 (6 by maintainers)
in my case the problem was the bootstrap version, I was using version 4.0.0-alpha.6 and I was using a method from an old version
<ul role = "tablist"><li>the class = ‘active’ is no longer going, it is<li class = "nav-item"><a>aggregate<a class="nav-link active">final structure in my case
https://jsfiddle.net/tsathianathan/heyfshLy/
fixed my issue through remove bt functionality with little custom code $(‘#containerContainingTabs a’).on(‘click’, function(e) { e.preventDefault(); $(this).tab(‘show’); var theThis = $(this); $(‘#containerContainingTabs a’).removeClass(‘active’); theThis.addClass(‘active’); });
#containerContainingTabs is the id on div which container tabs links
I have been using this as a workaround for now:
I would normally but there are countless issues of the same problem on here spanning a number of years and it still hasn’t been addressed despite all with activity and closed as duplicates etc.
If I find the time at some point, I’ll try and raise a new issue 👍
FWIW, this breaks it for keyboard users
You need to use
e.preventDefault()exactly as the Bootstrap Documentation stated:I have got the same problem as @tomkel and @chris13524 mentioned.
I use this in Bootstrap 3, simple and clean:
Things have changed in Bootstrap 4. The above example
The issue is mentioned also here https://github.com/twbs/bootstrap/issues/20523.
here are the v4 jsfiddles: working not working