I would like to know, how can I skip first N elements in JQuery. Something like this:
<div id="test">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
...
</div>
$('#test > div').skip(2)
Should return
<div>3</div>
<div>4</div>
...
I know I can just use :not(:first-child):not(:first-child + div)...
selector N times, but is there a better way?
jQuery has a gt selector. (Greater than).
$('#test > div:gt(1)')
Or you can use the slice function
$('#test > div').slice(2)
Use the .slice() function, it gives you the subset of elements based on its index.
$('#test > div').slice( 2 )
Reference: http://api.jquery.com/slice/
I think you are looking for the :gt
selector: http://api.jquery.com/gt-selector/
Note that you start counting from 0 here.
Try:
$('#test > div:gt(1)')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With