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();
    }

});

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

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