Assuming I have something like this:
<div class="testdiv">
<a href="/link1">link 1</a>
</div>
<div class="testdiv">
<a href="/link2">link 2</a>
</div>
<div class="testdiv">
<a href="/link3">link 3</a>
</div>
<div class="testdiv">
<a href="/link4">link 4</a>
</div>
Now I want select all <div>s of class testdiv except the div that has a child <a> with attribute href="/link3", how to do that with jQuery?
I know I can do this:
$('div.testdiv')
With
:not+:hasit can be done easily with one selector:If you don’t quote the value in the attribute (“CSS identifiers”) you need to escape the slash(
/) with two backslashes (\\):Live DEMO
If There can be only one anchor in a div, you can use this: