Skip to content

Instantly share code, notes, and snippets.

@nocodesupplyco
Created December 19, 2022 16:14
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 nocodesupplyco/9340dfc306b0df77f982c9c50a8b0a1f to your computer and use it in GitHub Desktop.
Save nocodesupplyco/9340dfc306b0df77f982c9c50a8b0a1f to your computer and use it in GitHub Desktop.
Set URL From Tab Change
$(function () {
function doChangeTab() {
var tabName = window.location.hash.substr(1);
var $tabTrigger = $('[data-tab-name="' + tabName + '"]');
if ($tabTrigger.length) {
$tabTrigger.click();
}
}
//when page is first loaded
if (window.location.hash) {
doChangeTab();
}
//internal page linking
$(window).on("hashchange", doChangeTab);
$("[data-w-tab]").on("click", function () {
history.pushState({}, "", "#" + $(this).data("tabName"));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment