Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
Twitter Bootstrap 5 Tabs: Go to Specific Tab on Page Reload or Hyperlink

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();
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Assuming the tab trigger is from a <ul> list, and the query string hash is the target in the href, then the Bootstrap 5 method for showing a tab when the page loads would be:

<ul class="nav nav-tabs">
  <li class="nav-item">
    <a class="nav-link" data-bs-toggle="tab" href="#someTarget">Some Target</a>
  </li>
</ul>
document.addEventListener("DOMContentLoaded", () => {
  const trigger = document.querySelector(`ul.nav a[href="${window.location.hash}"]`)
  const tab = new bootstrap.Tab(trigger)
  tab.show()
})

The above does not check for invalid query string hash names or valid dom elements; add as-needed.

about 4 years ago · Juan Pablo Isaza Report

0

Currently solved this with:

var hash = location.hash.replace(/^#/, "");
if (hash) {
  var triggerEl = document.querySelector("#" + hash + "-tab");
  triggerEl.click();
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!