8

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

Andrew Whitaker
  • 124,656
  • 32
  • 289
  • 307
Bart
  • 4,830
  • 16
  • 48
  • 68

6 Answers6

12

Please try with Index

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

It will returns the index of selected li or tab.

kbvishnu
  • 14,760
  • 19
  • 71
  • 101
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');
    }
});
Chris Porter
  • 3,627
  • 25
  • 28
1

I'm using something like this:

$tabContainer.tabs({
    activate: function (event, ui) {
        if (ui.newPanel.is("#TabId")) {
            // do sth here
        }
    }
});
1

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

sk747
  • 31
  • 4
  • Correct, jQuery adds the class `ui-state-active` to the active tab. See http://jqueryui.com/demos/tabs/ with Firebug to see how it works. – Scott Oct 29 '10 at 04:21
  • i need to check it programmatically, so i can do actions related to that – Bart Oct 29 '10 at 04:35
  • var selected = $tabs.tabs('option', 'selected'); // => 0 – Bart Oct 29 '10 at 04:36
0
var selectedTabIndex = 0;
jQuery("#tabContainer").tabs({
 select: function(event, ui) { 
  selectedTabIndex = ui.index; 
 }
});

You can use selectedTabIndex in your app

kalpesh patil
  • 81
  • 1
  • 5
0
var index = $("#tabs").tabs('option', 'selected');
Bartek
  • 1