Say I have a div
containing an unlimited number of child div
s. 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 div
s)?
Say I have a div
containing an unlimited number of child div
s. 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 div
s)?
3 Answers
Reset to default 15You can use the ":gt()" selector:
// div's 10 and higher
$('div:gt(9)').show()
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();