Created
June 20, 2013 05:54
-
-
Save meSingh/5820590 to your computer and use it in GitHub Desktop.
Link to a specific tab in bootstrap
This file contains 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
var gotoHashTab = function (customHash) { | |
var hash = customHash || location.hash; | |
var hashPieces = hash.split('?'), | |
activeTab = $('[href=' + hashPieces[0] + ']'); | |
activeTab && activeTab.tab('show'); | |
} | |
// onready go to the tab requested in the page hash | |
gotoHashTab(); | |
// when the nav item is selected update the page hash | |
$('.nav a').on('shown', function (e) { | |
window.location.hash = e.target.hash; | |
}) | |
// when a link within a tab is clicked, go to the tab requested | |
$('.tab-pane a').click(function (event) { | |
if (event.target.hash) { | |
gotoHashTab(event.target.hash); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment