I have the following html:
<div class="list">
<div class="sortable">
<div class="contentItem"> Some content </div>
<div class="contentItem"> Some content </div>
<div class="contentItem"> Some content </div>
</div>
</div>
<div class="list">
<div class="sortable">
</div>
</div>
<div class="list">
<div class="sortable">
<div class="contentItem"> Some content </div>
<div class="contentItem"> Some content </div>
<div class="contentItem"> Some content </div>
</div>
</div>
<div class="list">
<div class="sortable">
</div>
</div>
and i am trying to hide all of the "list" classes that don't have any "contentItem" divs inside of them. So its basically taking this
$(".list").hide();
which would hide all but ignore the ones that have "contentItem" elements in them
is this possible as a jquery selector?
Use :not() and :has()
$(".list:not(:has('.contentItem'))").hide();
Fiddle Demo
You can use :not()
along with :has()
pseudo selector to accomplish your task.
Try,
$(".list:not(:has('.contentItem'))").hide();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With