Bootstrap's JavaScript provides a tab('show') method that you call on the tab element's jQuery object to activate it properly. Simply adding the active class or triggering a click event won't update the tab content correctly.
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="home-tab" data-bs-toggle="tab" href="#home" role="tab">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" id="profile-tab" data-bs-toggle="tab" href="#profile" role="tab">Profile</a>
</li>
</ul>Which JavaScript snippet correctly activates the Profile tab using Bootstrap 5's JavaScript API?
Bootstrap 5 uses the bootstrap.Tab class. You create a new instance with the tab element and call show() to activate it. The jQuery method tab('activate') does not exist in Bootstrap 5.
Activating a tab highlights its label and shows its associated content panel. The previously active tab's content is hidden. Bootstrap handles this automatically when you call show() on a tab.
The active tab link in Bootstrap has the class active on the .nav-link element. The .nav-item does not get active class, and .tab-pane is for content panels, not tab links.
The aria-selected="true" attribute on the active tab link signals to screen readers that this tab is currently selected. Other attributes like aria-expanded or aria-checked are not used for tabs.
