Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
so i try to href links with specific table IDs so that when the link is opened the specific table id called will be the active tab opened( ie. www.gohome.com/asset.html#profile). but no matter what i do the active tab still remains stagnant and specifically calling out tab id's dont seem to do anything. im starting to think it cant be done without me implementing some sort of script. but im not that good at coding. any form of help will be great. thanks n advance.

What I have tried:

HTML
<div class="tab-content">
 <div class="tab-pane active" id="profile">
  <div class="single-service">
   <h3>me</h3>
  </div>
 </div>

 <div class="tab-pane " id="messages">
  <div class="single-service">
   <h2>you</h2>
  </div> 
 </div>
</div>


<ul class="nav nav-tabs">
 <li><a href="#profile">me </a></li> <li><a href="#messages">you</a></li>              </ul>
Posted
Updated 19-Jul-18 9:51am
v3

1 solution

Something like this should work, assuming you're using the standard Bootstrap 3 tabs[^]:
<script>
$(function () {
    var target = location.hash;
    if (target) {
        $("a[data-toggle='tab'][href='" + target + "']").tab("show");
    }
});
</script>
 
Share this answer
 
Comments
Member 13917192 19-Jul-18 15:59pm    
i feel this should work but it isnt. basically the script can go anywhere in the code right? or should it be in the code head?
Richard Deeming 20-Jul-18 7:12am    
As I said, it depends on your code matching the standard Bootstrap markup.

Looking at the code you posted in your question, your tab links are missing the data-toggle="tab" attribute. That will prevent the Bootstrap script from switching between the tabs, and will prevent this script from finding them.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900