Skip to content

Instantly share code, notes, and snippets.

@griiettner
Created July 31, 2014 18:52
Show Gist options
  • Save griiettner/52d9743193e4d07ad9c8 to your computer and use it in GitHub Desktop.
Save griiettner/52d9743193e4d07ad9c8 to your computer and use it in GitHub Desktop.
Bootstrap 3: Keep selected tab on page refresh
$('#myTab a').click(function (e) {
e.preventDefault();
$(this).tab('show');
});
// store the currently selected tab in the hash value
$("ul.nav-tabs > li > a").on("shown.bs.tab", function (e) {
var id = $(e.target).attr("href").substr(1);
window.location.hash = id;
});
// on load of the page: switch to the currently selected tab
var hash = window.location.hash;
$('#myTab a[href="' + hash + '"]').tab('show');
// Ref: http://stackoverflow.com/questions/18999501/bootstrap-3-keep-selected-tab-on-page-refresh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment