Created
May 2, 2013 18:32
-
-
Save rafamoreira/5504281 to your computer and use it in GitHub Desktop.
Bootstrap tabs with ajax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul id="MainTabs" class="nav nav-tabs"> | |
<li><a data-target="#apple" data-toggle="tab" href="/apple.html">apple</a></li> | |
<li><a data-target="#banana" data-toggle="tab" href="/banana.html">banana</a></li> | |
<li><a data-target="#cherry" data-toggle="tab" href="/cherry.html">cherry</a></li> | |
</ul> | |
<div class="tab-content"> | |
<div class="tab-pane" id="apple">Loading...</div> | |
<div class="tab-pane" id="banana">Loading...</div> | |
<div class="tab-pane" id="cherry">Loading...</div> | |
</div> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { | |
$("#MainTabs").tab(); | |
$("#MainTabs").bind("show", function(e) { | |
var contentID = $(e.target).attr("data-target"); | |
var contentURL = $(e.target).attr("href"); | |
if (typeof(contentURL) != 'undefined') | |
$(contentID).load(contentURL, function(){ $("#MainTabs").tab(); }); | |
else | |
$(contentID).tab('show'); | |
}); | |
$('#MainTabs a:first').tab("show"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment