jQuery的添加类到某些列表项 [英] JQuery Add class to certain list item
本文介绍了jQuery的添加类到某些列表项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试添加一个脚本,该脚本会将一个类添加到我选择的列表项中.
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");
我在做什么错了?
推荐答案
使用.eq()
$('.navigation ul li').eq(0).addClass("active");
为什么get()
没有起作用?看到这个-
jQuery:eq()vs get()
Why get()
didn't worked ? see this -
jQuery : eq() vs get()
这篇关于jQuery的添加类到某些列表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文