Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery UI - reload selected tab?

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.

like image 248
Renari Avatar asked Aug 06 '10 19:08

Renari


1 Answers

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);
like image 92
Simen Echholt Avatar answered Oct 19 '22 10:10

Simen Echholt