Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
28
rated 0 times [  29] [ 1]  / answers: 1 / hits: 9296  / 11 Years ago, sun, february 2, 2014, 12:00:00

In my page i use bootstrap's tab, but when i click each of tab, content of tab doesn't show correctly, this is my code:



<div class=w470px exam style=border: 1px solid #ddd; margin-top: 30px;>
<ul id=myTab class=nav nav-tabs nav-justified>
<li class=active><a href=#tab-home data-value=#home data-toggle=tab>Home</a></li>
<li><a href=#tab-fav data-value=#fav data-toggle=tab>Favoriets</a></li>
<li><a href=#tab-fr data-value=#fr data-toggle=tab>Friends</a></li>
<li><a href=#tab-ex data-value=#ex data-toggle=tab>Experience</a></li>
</ul>
<div id=myTabContent class=tab-content>
<div class=tab-pane fade in active id=tab-home>
HOME
</div>
<div class=tab-pane fade active id=tab-fav>
My favoriets
</div>
<div class=tab-pane fade active id=tab-fr>
My Friends
</div>
<div class=tab-pane fade active id=tab-ex>
My experience
</div>
</div>
<script type=text/javascript>
$(function () {
var navTabs = $('.nav-tabs a');
var hash = window.location.hash;
hash && navTabs.filter('[data-value=' + hash + ']').tab('show');

navTabs.on('shown', function (e) {
var newhash = $(e.target).attr('data-value');
window.location.hash = newhash;
});
})
</script>
</div>


JSFIDDLE



Where am i wrong? How can i fix it?


More From » jquery

 Answers
18

You have active class on all tab-pane divs. Remove it from all of them but the first one. BTW, in bootstrap 3, the event it is not show, it is shown.bs.tab Bootstrap 3 tabs.



I personally use this code: Twitter Bootstrap Tabs: Go to Specific Tab on Page Reload or Hyperlink, the only change I made, was to replace the on('show' with on('shown.bs.tab' .


[#48143] Friday, January 31, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
chase

Total Points: 78
Total Questions: 106
Total Answers: 93

Location: Comoros
Member since Tue, Mar 14, 2023
1 Year ago
chase questions
Thu, Mar 31, 22, 00:00, 2 Years ago
Thu, Jul 1, 21, 00:00, 3 Years ago
Sat, Dec 12, 20, 00:00, 4 Years ago
Mon, Sep 14, 20, 00:00, 4 Years ago
;