Skip to content

Instantly share code, notes, and snippets.

@meSingh
Created June 20, 2013 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meSingh/5820590 to your computer and use it in GitHub Desktop.
Save meSingh/5820590 to your computer and use it in GitHub Desktop.
Link to a specific tab in bootstrap
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