V
V
Vadim Timoshenko2018-05-21 18:16:56
JavaScript
Vadim Timoshenko, 2018-05-21 18:16:56

How to activate tabs in bootstrap with another button?

I use bootstrap 4 tabs ( link to documentation )
It is necessary to switch tabs not only through the tabs themselves, but also with the help of separate buttons in another part of the site. The meaning is this: I click on the menu and scroll to the tabs in the desired tab. I scrolled, but switching the tab does not work.
The code is like this:

<a class="nav-link" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">Другая ссылка</a>

<ul class="nav nav-tabs" id="myTab" role="tablist">
  <li class="nav-item">
    <a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">Home</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">Profile</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" id="contact-tab" data-toggle="tab" href="#contact" role="tab" aria-controls="contact" aria-selected="false">Contact</a>
  </li>
</ul>
<div class="tab-content" id="myTabContent">
  <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">...</div>
  <div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">...</div>
  <div class="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">...</div>
</div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tyzberd, 2018-05-21
@PbI6A_KuT

$('#someTab').tab('show') call on click

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question