get the current tab in jQuery UI tabs

后端 未结 11 1128
無奈伤痛
無奈伤痛 2021-01-01 16:46

I am using jQuery UI Tabs inside of the jQuery UI dialog window.

I\'ve come across an instance, where I need to find the id of the current tab when clicking on one o

11条回答
  •  清歌不尽
    2021-01-01 17:34

    This also works, using JQuery 3.1.1 and Jquery UI 1.12.1, when you need to select your active tab in javascript (by "select" I mean in a JQuery selector, not "select" in the sense of making the tab active, since of course the tab is already active).

    To get a reference to the currently selected tab, first get a reference to the active link (substitute the id of your tabs container "myTabs"):

    var $link = $('div[id=myTabs] ul .ui-tabs-active');
    

    $link has the id the tab in the attribute "aria-controls":

    var $tab = $('#' + $link.attr('aria-controls'));
    

    $tab is a reference to the tab body. For example, you could call

    $tab.html('[html here]') 
    

    to fill or replace the tab content.

提交回复
热议问题