user695663 user695663 - 1 year ago 140
jQuery Question

Jquery UI tabs. How to select a tab based on its id not based on index

Hi i have a two tabs and configured usign Jquery UI.

ul class="tabs"
li tabone
li tabtwo

dynamically from C# code behind i will hide or select some tab let say tabtwo
and the other tab has to be hidden or not shown. i can do this in java script using
but i dont want to use the tab indexes to do so.
is there any alternate to select tabs based on their name/id???

Answer Source

Note: Due to changes made to jQuery 1.9 and jQuery UI, this answer is no longer the correct one. Please see @stankovski's answer below.

You need to find the tab's index first (which is just its position in a list) and then specifically select the tab using jQuery UI's provided select event (tabs->select).

var index = $('#tabs ul').index($('#tabId'));
$('#tabs ul').tabs('select', index);

Update: BTW - I do realize that this is (ultimately) still selecting by index. But, it doesn't require that you know the specific position of the tabs (particularly when they are dynamically generated as asked in the question).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download