Reputation: 2277
Im trying to hide a div if another div is empty, but for some reason it wont work as I want.
so basically I want to hide the <div class="more_post">
if the <div class="last_post">
element is empty
<div id="toggle-view">
<div class="more_post">
<h5>Load more</h5>
</div>
<ul class="toggle-view">
<div class="toggle"">
<div class="last_post"> </div>
</div>
</ul>
</div>
Jquery
if($("#toggle-view ul.toggle-view .toggle .last_post").length ==0)
{
$("#toggle-view .more_post").hide();
}
Upvotes: 1
Views: 4821
Reputation: 4624
Try this out. It will work Simple method.
<script>
$(document).ready(function(){
if(!$.trim( $(".last_post").html() ) == true)
$(".more_post").hide();
});
</script>
Thank you
Upvotes: 1
Reputation: 54821
Try:
$("#toggle-view .more_post").toggle($("#toggle-view ul.toggle-view .toggle .last_post").html().length > 0);
Upvotes: 1
Reputation: 32807
Add .html()
to read the HTML from the DIV first.
if($("#toggle-view ul.toggle-view .toggle .last_post").html().length ==0)
{
$("#toggle-view .more_post").hide();
}
Upvotes: 1
Reputation: 4489
Try
if($("#toggle-view ul.toggle-view .toggle .last_post").html().length ==0)
{
$("#toggle-view .more_post").hide();
}
Upvotes: 1
Reputation: 172628
You can try something like this:-
if $('#toggle-view ul.toggle-view .toggle .last_post').is(':empty') $(this).hide()
Upvotes: 1