可以禁用空段落<p> </p>

时间:2013-08-08 14:09:59

标签: jquery editor paragraphs

如果我从我的cms编辑器<p></p>获取,可以删除空段落吗?我已经找到了如何在wordpress上删除它的方法,但我现在使用joomla,可能有可能禁用空的paragrahps wit jquery?

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

4 个答案:

答案 0 :(得分:2)

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

是你所要做的一切

答案 1 :(得分:1)

这将找到标记中没有文字的所有p代码:

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

Demo

答案 2 :(得分:1)

看起来像是工作,即使我建议使用.filter():

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

使用filter():

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

答案 3 :(得分:0)

你可以使用jquery:

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