Is it possible to hide a div with css if the div has no child div’s with a specific class name?
<div class="parent">
This div must be hidden
</div>
<div class="parent">
This div must be visible
<div class="child">
child div
</div>
</div>
If it’s not possible with CSS, maybe with javascript or jQuery?
I don’t think this is possible with just CSS, but it is definitely possible with Javascript.
You have to
– find all divs with class
parent– find all those with a child div with class
child– if there is no such child, set
style.display = noneNow, with pure javascript this can be a bit complicated. You can use the
getElementsByClassNamefrom this question and then apply the above logic:With jQuery, this is lot more simple:
Live Example: http://jsfiddle.net/nivas/JWa9r/