In a page where I have n tabs, and the following script (coffeescript, I checked the compiled javascript and it seems to be ok)…
JavaScript
x
8
1
$ ->
2
init()
3
4
init = ->
5
$('a[data-toggle="tab"]').on 'shown', (event) ->
6
shown = event.target
7
console.log("Showing tab: " + shown)
8
Now, the ‘shown’ event does not fire on page load, so for the first tab being shown on the page there’s no way to handle this (ie: loading content via xhr)
I tried adding this to the above script, to see if triggering it manually could work:
JavaScript
1
2
1
$('a[data-toggle="tab"]:first').tab 'show'
2
… but it didn’t.
This is the HTML code I use in my view
JavaScript
1
28
28
1
<div class="tabbable">
2
<ul class="nav nav-tabs">
3
<li class="active">
4
<a href="#updates" data-toggle="tab"><%=t :updates, :scope => 'user.profile.sections'%></a>
5
</li>
6
<li class="">
7
<a href="#activity" data-toggle="tab"><%=t :activity, :scope => 'user.profile.sections'%></a>
8
</li>
9
<li class="">
10
<a href="#articles" data-toggle="tab"><%=t :articles, :scope => 'user.profile.sections'%></a>
11
</li>
12
</ul>
13
14
<div class="tab-content">
15
<div class="tab-pane active" id="updates">
16
17
</div>
18
<div class="tab-pane" id="activity">
19
20
</div>
21
22
<div class="tab-pane" id="articles">
23
24
</div>
25
26
</div>
27
</div>
28
Any clue?
Advertisement
Answer
Try leaving the class active
off both the tab <li>
and the content <div>
. One of the first lines of code in the show()
method is to short-circuit if the tab being requested is already active.