How could you link to bootstrap 5 tabs directly as with previous bootstrap methods according to?:
Twitter Bootstrap Tabs: Go to Specific Tab on Page Reload or Hyperlink
I’ve tried the following approach:
var hash = location.hash.replace(/^#/, ""); // ^ means starting, meaning only match the first hash
if (hash) {
var someTabTriggerEl = document.querySelector("#" + hash + "");
var tab = new bootstrap.Tab(someTabTriggerEl);
tab.show();
}
2
Answers
Currently solved this with:
Assuming the tab trigger is from a
<ul>
list, and the query string hash is the target in thehref
, then the Bootstrap 5 method for showing a tab when the page loads would be:The above does not check for invalid query string hash names or valid dom elements; add as-needed.