user2327201
user2327201

Reputation: 409

JQuery Add class to certain list item

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

Answers (2)

Adil Shaikh
Adil Shaikh

Reputation: 44740

Use .eq()

$('.navigation ul li').eq(0).addClass("active");

http://api.jquery.com/eq/


Why get() didn't worked ? see this - jQuery : eq() vs get()

Upvotes: 8

Memolition
Memolition

Reputation: 494

use .children().eq()

$('.navigation ul').children().eq(0).addClass('class');

Upvotes: 2

Related Questions