最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - selecting nth div (and beyond) in jQuery - Stack Overflow

programmeradmin3浏览0评论

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

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

Share Improve this question edited Jan 19, 2009 at 19:55 Pim Jager 32.1k17 gold badges74 silver badges99 bronze badges asked Jan 19, 2009 at 19:47 ceejayozceejayoz 180k41 gold badges309 silver badges380 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 15

You 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();
发布评论

评论列表(0)

  1. 暂无评论