Select element unless it has an ancestor of a given class using just a selector

后端 未结 5 904
孤街浪徒
孤街浪徒 2021-01-03 23:11

Suppose I have the following HTML:

  • One
  • Two
5条回答
  •  借酒劲吻你
    2021-01-03 23:23

    You can do it like this

    $("li").not('.foo li')
    

    http://jsfiddle.net/y7s54/

    or

    $("li:not(.foo li)")
    

    http://jsfiddle.net/QpCYY/

    Select all li's that don't have an ancestor with class foo

提交回复
热议问题