我正在使用
jquery并创建show hide列表,我需要隐藏ul中第6个孩子后面的所有子列表项.通常我会通过设置高度,然后点击一下点击更改高度来做到这一点,但为了这个工作,我需要添加溢出:隐藏到我的CSS,这不是一个选项.
如何获得大于第7个孩子的所有子列表元素?
就像是,
$(“ul li:6n”).domeSomething()
解决方法
How would I get all the child list elements that are greater than the 7th child?
选择元素index = 7
$("ul li:gt(6)").domeSomething()
选择器使用零基索引:
Note that since JavaScript arrays use 0-based indexing,these selectors reflect that fact. This is why $(‘.myclass:gt(1)’) selects elements after the second element in the document with the class myclass,rather than after the first. In contrast,:nth-child(n) uses 1-based indexing to conform to the CSS specification.