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

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

Suppose I have the following HTML:

  • One
  • Two
5条回答
  •  粉色の甜心
    2021-01-03 23:49

    You can do it using context along with selector as under,

    $('li', $('div:not(.foo)'))
    

    LIve Demo

    $('li', $('div:not(.foo)')).each(function(){
        alert($(this).text());
    });​
    

提交回复
热议问题