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

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

Suppose I have the following HTML:

  • One
  • Two
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-03 23:34

    How about this:

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

    The comments in the docs are quite useful if this doesn't work:

    http://api.jquery.com/not-selector/

提交回复
热议问题