Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all parents that don't have a child with a certain class

I want to select all div's of parents using jQuery, that don't have children with the class locked

Example code:

<div class='myparent'>
    <div class='mychild locked'></div>
</div>
<div class='myparent'>
    <div class='mychild locked'></div>
</div>
<div class='myparent'>
    <div class='mychild'></div>
</div>

I feel like I'm really close:

$('div.myparent:not(:has(div[class=locked]))')

But that does not work.

like image 534
David Schumann Avatar asked Mar 09 '23 10:03

David Schumann


1 Answers

You can just use class selector, there is no need for attribute selector DEMO

$('.myparent:not(:has(div.locked))')

Note:- you can do like this too:- $('.myparent:not(:has(.locked))')

like image 119
Nenad Vracar Avatar answered Mar 11 '23 04:03

Nenad Vracar