views:

682

answers:

3

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

+2  A: 

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();
pilif
Worked, but I'm going to go with the :gt() selector @Rob posted. Thanks though, have an upvote!
ceejayoz
yepp. the :gt() solution is much better because it does not retrieve elements just to throw them away afterwards. This is why I have upvoted Rob's answer too. Next time, I'll refrain from posting answers I don't *really* know.
pilif
+13  A: 

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

 // div's 10 and higher
 $('div:gt(9)').show()
Rob
Works like a charm, thanks!
ceejayoz
+2  A: 

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

$('div').css('color', 'red').filter(':gt(5)').remove();
Pim Jager