[英]Jquery selector for first 'one, two, three, and X' elements and :not()?
If you want to select the first element or :not, there are several choices: 如果要选择第一个元素或者不是,则有以下几种选择:
:not(:first)
:nth-child(1)
first()
:first-child
What are the options for selecting the first 'two, three, and X' elements? 选择第一个“两个,三个和X”元素有哪些选项?
AND 和
:not(the first two, three, and X?)
can the :not()
be accomplished by using the JS !
:not(the first two, three, and X?)
可以:not()
通过使用JS完成!
If the elements you want to exclude follow consecutively, you could use slice()
: 如果要排除的元素连续跟随,则可以使用
slice()
:
$(selector).slice(0,3);
This will select the first three elements, the 0
is the zero-based index of the first element to start, and the second, the 3
, is the zero-based index of the element at which to stop, collecting. 这将选择前三个元素,
0
是要开始的第一个元素的从零开始的索引, 第二个元素3
是要停止,收集的元素的从零开始的索引。
The second number can also be a negative number and, if so, will count from the end of the returned set of elements: 第二个数字也可以是负数,如果是,则从返回的元素集的末尾开始计算:
$(selector).slice(1,-3);
References: 参考文献:
There are a few ways: 有几种方法:
For just the first 1 or 2 you could specify using eq
: $('.class').eq(0);
对于前1或2,您可以使用
eq
: $('.class').eq(0);
指定$('.class').eq(0);
For a limited range, use lt
: $('.class').lt(3);
对于有限范围,请使用
lt
: $('.class').lt(3);
To perform the "not" of lt
, use gt
, which is greater-than. 要执行
lt
的“not”,请使用gt
,大于。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.