views:

121

answers:

1

I know that I can get the (numerical) index of the currently selected tab like this:

$('.selector').tabs('option', 'selected');

Is there a way to get the ID of the currently selected tab, outside of an event handler? By "ID" I'm referring to the string property (ui.panel.id) in the ui object that's passed in as an argument to an event listener callback - but I'm trying to do it outside of a callback.

I know I can hack together my own solution, but I want to make sure I'm not reinventing the wheel first.

I'd would rather work with IDs than indices so that changing the order of my tabs doesn't break my code - it's at least a little more robust and readable.

A: 

As far as I know, selected tab has class ui-tab-selected. You may use

$('.selector').find('.ui-tab-selected a');

to fetch selected tab. It was element, where href attribute - identifier of active panel.

Anatoliy
That doesn't work at all. the `ui-tab-selected` class goes on the `<li>` for whatever tab is selected, and there isn't an easy mapping to the ID from that `li` anyway (without getting the href property and stripping away the `#`). But it got me on the right track: `$('#Tab_ID:not(.ui-tabs-hide)');` will return a non-empty array if the tab with ID `Tab_ID` is not hidden.
Matt Ball