Reputation: 409
I am trying to add a script that will add a class to a list item that I choose..
I have tried this but it didnt add the class
$('.navigation ul li').get(0).addClass("active");
What Am i doing wrong?
Upvotes: 2
Views: 15372
Reputation: 44740
Use .eq()
$('.navigation ul li').eq(0).addClass("active");
Why get()
didn't worked ? see this -
jQuery : eq() vs get()
Upvotes: 8
Reputation: 494
use .children().eq()
$('.navigation ul').children().eq(0).addClass('class');
Upvotes: 2