举例如下:
在 class="phpernote" 下有 3个 ul,现在希望给每个ul下的第5个li元素添加 class="com"
具体jQuery代码:
$(".phpernote ul li:nth-child(5)").addClass("com");已经成功给每个ul下的第5个li添加class为com
当然,也可以直接添加 CSS 代码:
$(".phpernote ul li:nth-child(5)").css({"padding-right":"5px"});nth-child:英文中的缩写,n-th,表示第几个,1,2,3分别用 first、second、third 单词,从4开始便为数字的单词+th,如4th、5th、6th等等
获取ul下的第一个li
$("ul li:first-child")获取ul下的最后一个li
$("ul li:last-child")
Copyright © 2019- kushenhuo.com 版权所有
违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务