Skip first N elements in JQuery

后端 未结 4 1575
迷失自我
迷失自我 2020-12-11 00:40

I would like to know, how can I skip first N elements in JQuery. Something like this:

1
2&l
相关标签:
4条回答
  • 2020-12-11 01:04

    jQuery has a gt selector. (Greater than).

    $('#test > div:gt(1)')
    

    Or you can use the slice function

    $('#test > div').slice(2)
    
    0 讨论(0)
  • 2020-12-11 01:04

    Skip just the first one - example:

    $("#spaccordion li:gt(0)").addClass("collapsed");
    

    All <li> items will have class "collapsed" except the first one

    0 讨论(0)
  • 2020-12-11 01:12

    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)')
    
    0 讨论(0)
  • 2020-12-11 01:15

    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/

    0 讨论(0)
提交回复
热议问题