Remove empty tags and tags with just non-breaking space in jQuery

    [javascript]
    $(‘p’).each(function() {
    var $p = $(this),
    txt = $p.html();
    if (txt==’ ’) {
    $p.remove();
    }
    });

    $(‘p’)
    .filter(function() {
    return $.trim($(this).text()) === ”
    })
    .remove()
    [/javascript]

    Leave a Reply