jqueryjquery-uijquery-selectorsjquery-ui-tabsjquery-tabs

Force select a jQuery-ui-tab as default


At the moment, I have 2 separate functions which create tabs in the jquery tabs ui. It seems a bit random as to which tab generated from these 2 functions ends up being the tab which displays by default.

For example, if function tabs_a create 4 tabs, and function tabs_b create another 4 tabs, either the first tab from tabs_a is displayed as the default tab or the first tab from tabs_b is displayed as default.

How do I chose to display/select a specific tab automatically once both functions have finished loading/create the tabs?

For example, if function tabs_a creates:

tab_a_1
tab_a_2
tab_a_3
tab_a_4

and tabs_b creates:

tab_b_1
tab_b_2
tab_b_3
tab_b_4

at the moment, tab_a_1 or tab_b_1 will get selected by default, and it seems random which one of these 2 ends up getting selected by default.

How do I for example force tab_b_3 to become selected by default?


Solution

  • After the tabs are created, you can forcefully call the following

    $("#tabs").tabs('select', "#tab_b_3");
    

    Here, #tabs is the id of the div on which you have called the .tabs() function.