문제

Example:

<span>Bacon, Chris P.</span>
<span>Jones, Pete</span>
<span>Adams, Sam</span>
<span>Bacon, Chris P.</span>
<span>Jones, Pete</span>
<span>Adams, Sam</span>
<span>Bacon, Chris P.</span>

Using eq() to choose where to start, how can one use jQuery to select an arbitrary number of siblings? Such as span:eq(0) through span:eq(10)?

도움이 되었습니까?

해결책

jQuery slice():

$('<span>').slice(1, 10);

or you can use the :gt() selector combined with the :lt() selector:

$('<span>:gt(0):lt(10)'); // first 10 elements

Docs:

다른 팁

You could use nextUntil():

$('span:eq(2)').nextUntil( $('span:eq(6)') ).addBack()

jsFiddle example

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top