1

I have a jQuery tab. I have to select the second tab by default. But I have a problem with assigning the active class to the second li. Below is the code to add the active class to first li. How can I edit the code below to make second li active instead:

$("ul.tabs li:first").addClass("active");
insertusernamehere
  • 23,204
  • 9
  • 87
  • 126
Anoop
  • 252
  • 1
  • 4
  • 12
  • Possible Duplicate: http://stackoverflow.com/questions/7514448/how-to-get-a-specific-jquery-item-from-a-list-of-items – MackieeE Oct 30 '13 at 11:57

2 Answers2

3

Try using .eq():

$("ul.tabs li:eq(1)").addClass("active");
Dhaval Marthak
  • 17,246
  • 6
  • 46
  • 68
2

Try this,

$("ul.tabs li:eq(1)").addClass("active");

Read :eq-selector

or

$("ul.tabs li:nth-child(2)" ).addClass("active");

Read nth-child-selector

Using jquery ui option-active you can use

$( "ul.tabs" ).tabs({ active: 1 });
Rohan Kumar
  • 40,431
  • 11
  • 76
  • 106