How to get the link from a specific bootstrap tab

0

I have a page that uses the Tabs navs of bootstrap 4.1, I'm looking for and I can not find a solution, I want to make clicking a link open a specific 'bootstrap' tab. In this example:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script><linkhref="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>

<a href="#">Profile</a>
<br />
<br />
<nav>
  <div class="nav nav-tabs" id="nav-tab" role="tablist">
    <a class="nav-item nav-link active" id="nav-home-tab" data-toggle="tab" href="#nav-home" role="tab" aria-controls="nav-home" aria-selected="true">Home</a>
    <a class="nav-item nav-link" id="nav-profile-tab" data-toggle="tab" href="#nav-profile" role="tab" aria-controls="nav-profile" aria-selected="false">Profile</a>
  </div>
</nav>
<div class="tab-content" id="nav-tabContent">
  <div class="tab-pane fade show active" id="nav-home" role="tabpanel" aria-labelledby="nav-home-tab">Perfil</div>
  <div class="tab-pane fade" id="nav-profile" role="tabpanel" aria-labelledby="nav-profile-tab">Contato</div>
</div>

When you click the <a href="#">Profile</a> link it goes to the Profile tab. Because I want to do a redirect for a given URL with PHP, index.php?id=2#nav-profile , but if I call direct so it does not go to this second tab but rather it stays in the first #home.

    
asked by anonymous 24.10.2018 / 00:16

1 answer

1

You can use

<a href="#" onclick="document.getElementById('nav-profile-tab').click()">Profile</a>

I'm not sure if there is an option with pure HTML, this is an output with JavaScript.

    
24.10.2018 / 00:27