October 7, 2012

hide p element if empty

Question by user1726062

I want to use jQuery to hide a p element with class of .last_edit if the p element is empty. example

<p class="last_edit"></p>

<p class="last_edit">This would be displayed since there is text in it</p>

Does anyone know how t

Answer by Starx

There are many ways

$(".last_edit:empty").hide();

or

$(".last_edit").each(function() {

    if($.trim($(this).html()).length > 0) {
       $(this).hide();
    }

});
...

Please fill the form - I will response as fast as I can!