1

Having this html:

<div><h1>1</h1></div>
<div>2</div>
<div><h1>3</h1></div>

This is returning 0:

$("div").filter(":not(:not(:has(h1)))").length

I've made some testing here and the first two selectors are ok (without any filtering, and then just with one not).

This is a simpler model than my code. I really can't avoid both not's because one is added by a plugin and the other is being received in its options.

4

2 回答 2

2

Don't know why this is happening but it got fixed on version 1.8. Here is the same code with jQuery 1.8 working.

If you can't change your version for some reason one workaround is changing the .filter for .not. Here it is working.

于 2012-09-21T13:14:52.163 回答
0

Have you tried removing the double 'not's like this ?

alert($("div").length);
alert($("div").filter(":not(:has(h1))").length);
alert($("div").filter(":has(h1)").length);​
于 2012-09-21T13:41:27.583 回答