Question

Say I have a div containing an unlimited number of child divs. Is there an easy way to get jQuery to select the nth div and every div after it so I can change those (in this case, call remove() on old divs)?

Was it helpful?

Solution

You can use the ":gt()" selector:

 // div's 10 and higher
 $('div:gt(9)').show()

OTHER TIPS

Typing this out of my head and the jQuery API doc (read: this is not tested), but the first thing I'd do is to

$('#container div').slice(-n).remove();

Or if you need to do something with all divs first:

$('div').css('color', 'red').filter(':gt(5)').remove();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top