Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selected tab id?

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.

like image 559
oshirowanen Avatar asked Mar 14 '11 14:03

oshirowanen


People also ask

What is a tab ID?

ID is an identifier that allows the tab component to be referenced by other components in the page.

How to get selected tab ID in jQuery?

var selectedTab = $("#TabList"). tabs(). data("selected. tabs");


2 Answers

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/

like image 128
brendan Avatar answered Oct 27 '22 13:10

brendan


var id = $("li.tab:eq("+selected+")").attr('id');
like image 32
Eugene msc Avatar answered Oct 27 '22 11:10

Eugene msc