jquery selector - exclude first and second

前端 未结 5 1944
无人共我
无人共我 2021-02-13 11:56

I want to exclude first and second element from jquery selector. I tried this:

$(\'p:not(:nth-child(1),:nth-child(2))\')

But this only excludes

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-13 12:26

    This jQuery sequence uses .slice() to discard the first two elements from the $('p') selector:

    $('p').slice(2).
    

    see http://jsfiddle.net/alnitak/zWV7Z/

    Note that this is not the same as nth-child - the exclusion is based on the whole set of elements found in the first selector, and not on their relative position in the DOM.

提交回复
热议问题