Jquery UI - reload selected tab?

Renari picture Renari · Aug 6, 2010 · Viewed 60.3k times · Source

Is there a way to reload the selected tab I know there is the .load() function. But it wants a tab index and I don't seem to see a way to grab the selected tabs id.

Answer

Simen Echholt picture Simen Echholt · Aug 8, 2010

Update: In jQuery 1.9, the selected option is renamed to active. See attomman's answer.

To get the currently selected index, use the tabs('option','selected') function.

E.g, if you have a button #button (and the #tabs element is made into tabs) where you want to get the index, do the following:

$("#button").click(function() {
    var current_index = $("#tabs").tabs("option","selected");
});

Here's a demo: http://jsfiddle.net/sVgAT/


To answer the question indicated by the title, in jQuery 1.8 and earlier, you would do:

var current_index = $("#tabs").tabs("option","selected");
$("#tabs").tabs('load',current_index);

And in jQuery 1.9 and later, you would do:

var current_index = $("#tabs").tabs("option","active");
$("#tabs").tabs('load',current_index);