Skip to content

Instantly share code, notes, and snippets.

@Faizanq
Created June 25, 2019 05:49
Show Gist options
  • Save Faizanq/781e59292bbee595a02cb737c8199932 to your computer and use it in GitHub Desktop.
Save Faizanq/781e59292bbee595a02cb737c8199932 to your computer and use it in GitHub Desktop.
Keep selected tab on page refresh
$(document).ready(function() {
if (location.hash) {
$("a[href='" + location.hash + "']").tab("show");
}
$(document.body).on("click", "a[data-toggle='tab']", function(event) {
location.hash = this.getAttribute("href");
});
});
$(window).on("popstate", function() {
var anchor = location.hash || $("a[data-toggle='tab']").first().attr("href");
$("a[href='" + anchor + "']").tab("show");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment