选择除一个之外的所有div
not me
我们如何编写一个选择器来选择all divs with class b
除了哪个孩子是
not me
?
$('div.b:not(:has(p))').........
或者是可读的版本
$('div.b').filter(function(){ return !$(this).find('p').length; });
如果您还想匹配内容:
$('div.b').filter(function(){ return $(this).find('p').text() !== "not me"; });
现场演示
演示 http://jsfiddle.net/46nC5/1/
因为你是专门寻找class b
为你做一个演示因此共享。
在这个演示中,您将看到不是我逐渐淡出,rest将保持不变。
即:not
使用:not
+ :has
可以做到
码
$('div.b:has(p)').
要么
$('div.b:not(:has(p))')
$('div.b').filter(function () { return $(this).find('p:contains(not me)').length == 0; })
jsFiddle演示
我通常做的最好的方法:
$('div.b').filter(function () { return !$(this).hasClass('notMe'); }); not me
这将给你两个div ,他们有class =“b”而且没有p (段落)
现场演示
$('div.b:not(:has(p))')
这是另一个
$("div.b:contains('not me')")
编辑:对不起,这里没有
$("div.b:not(:contains('not me'))")