I have a setup that looks something like this:
<div class="parent">
<div class="child1">Header</div>
<div class="child2">
<div class="grandchild"></div>
<div class="grandchild"></div>
<div class="grandchild"></div>
</div>
</div>
My goal is to hide the parent div when .child2 contains no elements. I've attempted this solution, but it doesn't seem to be working:
$(".child2:empty").parent().hide();
Could you point out what might be going wrong? Feel free to check out my sample fiddle.
UPDATE:
I should clarify that instead of .child2 being empty, I actually want the children divs of .child2 to have a display:none property. You can see the revised version of my fiddle here