Reputation: 1187
Hi I have the following HTML structure as an example:
<body>
Testing hiding DIVs
<div class="content-1">
<h2>Hello - this is div 1</h2>
<div class="content-2">
<h2>Hello - this os div 2</h2>
</body>
I would like to hide div "content-2" only if div"content-1" contains or has content within it.
What would be the easiest way to achieve this using jquery?
Many thanks for any suggestions...
Upvotes: 0
Views: 169
Reputation: 10243
if($(".content-2").html().length > 0)
$(".content-1").hide();
EDIT- misread this initially-- changed boolean expression.
Upvotes: -1
Reputation: 20494
if ($('div.content-1:not(:empty)').length) $('div.content-2').hide();
Upvotes: 1
Reputation: 44740
You can try this - (you should close your div
though)
if($('.content-1').contents().length > 0){
$('.content-2').hide();
}
Upvotes: 5