Remove elements with only a   space using jQuery

Viewed 22790

Is there a way to remove this

<p> </p>

using jQuery?

8 Answers

This could be a better solution for CMSs. Some rich text editors add &nbsp; inside empty paragraphs.

    $("p").filter( function() {

        var html = $(this).html();

        if(html == '' || html == '&nbsp;')
            return true;

    }).addClass('emptyP');
Related