It's possible to disable empty Paragraphs <p>

115 Views Asked by At

if i get from my cms editor<p></p> it's possible to delete empty paragraphs? I have found the way how it is possible to delete at wordpress, but i use now joomla, may be possible to disable empty paragrahps wit jquery?

https://wordpress.stackexchange.com/questions/17248/how-to-disable-empty-p-tags-in-comment-text

4

There are 4 best solutions below

1
On

This will find all p tags that have no text within the tag:

$('p').each(function() {
     if ($(this).text() == "") {
         $(this).remove();
     }
});

Demo

0
On

you can use jquery:

$("p").each(function () {  
    if ($(this).html().trim().length === 0) {
        $(this).remove();
    }
});
0
On
$("p:empty").remove();

is all you have to do

0
On

Looks like work, even i'd suggest to use .filter():

$('p:empty').remove();

Using filter():

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