Created
January 21, 2020 05:24
-
-
Save 0x962/ed75f939b61b358643d9593f49bbb8b2 to your computer and use it in GitHub Desktop.
Bootstrap Auto Tab Open
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
$(document).on('ready', function () { | |
// open tab when page is loaded if hash is present in the URL | |
let activeTab = document.location.hash || '#details'; // your default tab here | |
$(`[href='${activeTab}']`).not('.no-auto-tab').tab("show"); // add .no-auto-tab if you don't want it to automatically open | |
// update location hash as tabs are switched | |
$('a[data-toggle="tab"]').not('.no-auto-tab').on('shown.bs.tab', function (e) { | |
e.preventDefault(); | |
window.location.hash = $(e.target).attr("href"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment