how do i check which tabs is active using jquery tabs?
Asked Answered
W

6

8

how do i check which tabs is active using jquery tabs?

Wunder answered 29/10, 2010 at 3:57 Comment(0)
C
12

Please try with Index

 function getIndex(){
     return $("ul li.ui-state-active").index();
    }

It will returns the index of selected li or tab.

Calvaria answered 29/10, 2010 at 4:42 Comment(0)
S
2

I needed to get the active tab during the activate event. I was able to do this using the option active call.

$('#tabs').tabs({
    activate: function (event, ui) {
        var activeTabId = $(this).tabs('option', 'active');
    }
});
Shufu answered 19/10, 2012 at 5:32 Comment(0)
R
1

Not too sure about this but I think jQuery dynamically assigns a class of 'ui-state-active'

Rhinarium answered 29/10, 2010 at 4:14 Comment(3)
Correct, jQuery adds the class ui-state-active to the active tab. See jqueryui.com/demos/tabs with Firebug to see how it works.Snowdrop
i need to check it programmatically, so i can do actions related to thatWunder
var selected = $tabs.tabs('option', 'selected'); // => 0Wunder
E
1

I'm using something like this:

$tabContainer.tabs({
    activate: function (event, ui) {
        if (ui.newPanel.is("#TabId")) {
            // do sth here
        }
    }
});
Enforce answered 28/7, 2014 at 15:7 Comment(0)
A
0
var index = $("#tabs").tabs('option', 'selected');
Additive answered 22/6, 2011 at 14:23 Comment(1)
The selected option is delayed by 1 click if you are accessing the value in the activate event.Shufu
A
0
var selectedTabIndex = 0;
jQuery("#tabContainer").tabs({
 select: function(event, ui) { 
  selectedTabIndex = ui.index; 
 }
});

You can use selectedTabIndex in your app

Accumulate answered 28/10, 2015 at 7:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.