Search code examples
jquery-uijquery-ui-tabs

jQueryUI Tab - Selected TabText on demand


I need a function which will get the text of the currently selected tab. I can get the selected tab using events, but I need to get the text even if the selected event is not yet thrown.

Here's my event script,

    $( "#tabs" ).bind( "tabsselect", function(event, ui) {
         _textOfTab=$(ui.tab).text();
     });

How can I just query the tabs for the currently selected one?


Solution

  • The <li> of the selected tab will have a ui-tabs-selected class on it, you can use that to find the active tab.

    $("#tabs ul.ui-tabs-nav li.ui-tabs-selected").text()
    

    You can test it out here.