Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Click event in bootstrap 3 tabs

I have the following HTML:

<div id="channels">
    <ul class="nav nav-tabs" id="ul-channels">
        <li class="channel" data-roomid="lobby"><a class="link-channel" href="#lobby" data-toggle="tab">lobby</a></li>
        <li class="channel active selected" data-roomid="test"><a class="link-channel" href="#test" data-toggle="tab">test</a></li>
    </ul>
</div>

I need an event that occurs when switching tabs. Like this:

$('.nav-tabs a').click(function (e) {
    alert("Q");
});

I tried a lot of options, but I had no success. I will appreciate any help.

like image 530
Denis Avatar asked Sep 30 '13 14:09

Denis


People also ask

How do I show tabs in bootstrap?

To make the tabs toggleable, add the data-toggle="tab" attribute to each link. Then add a . tab-pane class with a unique ID for every tab and wrap them inside a <div> element with class . tab-content .

What are pills in bootstrap?

Bootstrap 5 Pills component. Pills are quasi-navigation components which can highly improve website clarity and increase user experience.

How do I make the first tab active in bootstrap?

You can activate a tab or pill navigation without writing any JavaScript by simply specifying data-toggle="tab" or data-toggle="pill" on an element. Use these data attributes on .

How do I change the active tab color in bootstrap?

You can always modify your navigation list through css. Use this css code instead, in that way use you use the a tag to change the color and its background-color. It's improper to use the li tag to set the background only and a tag to set the color of the text.


1 Answers

The final my solution:

$(document).on( 'shown.bs.tab', 'a[data-toggle="tab"]', function (e) {
   console.log(e.target) // activated tab
})
like image 124
Denis Avatar answered Oct 03 '22 06:10

Denis