Question

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)?

Was it helpful?

Solution

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:

OTHER TIPS

You could use nextUntil():

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

jsFiddle example

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top