Remove elements with only a   space using jQuery

Try:

$('p')
    .filter(function() {
        return $.trim($(this).text()) === '' && $(this).children().length == 0
    })
    .remove()

What that does is it finds all the <p>s that have nothing in them, and removes them from the DOM.

Leave a Comment