Find Active Tab using jQuery and Twitter Bootstrap

后端 未结 3 635
失恋的感觉
失恋的感觉 2020-12-28 11:39

I\'ve been racking my brain for a little while now, and I would like to know if anyone out there knows how I can find the active tab, using jQuery and Twitter\'s Bootstrap.

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-28 12:00

    Twitter Bootstrap assigns the active class to the li element that represents the active tab:

    $("ul#sampleTabs li.active")
    

    An alternative is to bind the shown event of each tab, and save the active tab:

    var activeTab = null;
    $('a[data-toggle="tab"]').on('shown', function (e) {
      activeTab = e.target;
    })
    

提交回复
热议问题