barnamah
barnamah

Reputation: 59

jquery tabs selected is not working

I have 2 tabs and would like to select the 2nd as selected/active. I don't know what is the difference between active/selected but this code doesn't work:

$(function() {
  $( "#tabs" ).tabs();
  $( "#tabs" ).tabs({ selected: "#tabs-1" });
});

I changed it to:

$(function() {
  $( "#tabs" ).tabs();
  $( "#tabs" ).tabs({ selected: 2 });
});

and change the selected: 2 to 1 or 0 but no luck.

I would when the user clicks a tab, cookie should record the selection and when visitor visits next time, the remembered tab should be active. thanks

Upvotes: 0

Views: 3598

Answers (1)

andi
andi

Reputation: 6522

selected is not a valid attribute for the jQuery UI tabs widget. You need to use active. http://api.jqueryui.com/tabs/

The reason this code doesn't work is because you initialize the tabs widget twice:

$(function() {
    $( "#tabs" ).tabs(); //initialize tabs without specifying selected.
    $( "#tabs" ).tabs({ selected: 2 }); //doesn't work
});

Either do this:

$(function() {
    $( "#tabs" ).tabs({ active: 2 });
});

or this:

$(function() {
    $( "#tabs" ).tabs();
    $( "#tabs" ).tabs( "option", "active", 2 );
});

Upvotes: 4

Related Questions