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

前端 未结 14 2214
刺人心
刺人心 2020-12-25 11:07

I have two tabs and configured usign jQuery UI.

ul  class=\"tabs\"
  li  tabone
  li tabtwo
ul

dynamically from C# code behind I will hide

14条回答
  •  梦谈多话
    2020-12-25 11:41

    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).

提交回复
热议问题