Selected tab id?

oshirowanen picture oshirowanen · Mar 14, 2011 · Viewed 26.8k times · Source

I have the following script which gets the index of the selected tab:

http://jsfiddle.net/oshirowanen/eWncA/

Is it possible to get the id instead, if the li's had id's. If it is easier to get it from elsewhere, then that would also be fine, i.e. the related div tags, or somewhere else.

Answer

brendan picture brendan · Mar 14, 2011

jQuery UI just adds a class to the selected li. You could just pull the li with the selected class out like this:

   var id = $("li.tab.ui-tabs-selected").attr("id");

If you wanted to get one of the unselected tabs you could do something like this:

var id = $("li.tab:not(.ui-tabs-selected)").first().attr("id");

Working example:

http://jsfiddle.net/UBs9m/2/