删除只包含空格的空元素 [英] Remove empty elements, that only contain white spaces
本文介绍了删除只包含空格的空元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从我的页面中删除空的 <p></p>
.这适用于 $('p:empty').remove();
.但我的页面上也有一些 <p>
,看起来像这样(只包含很多空格):
I want to remove empty <p></p>
from my page. This works great with $('p:empty').remove();
. But I also have some <p>
's on my page, that look like this (only containing a lot of white spaces):
<p>
</p>
不幸的是,它们不被识别为空.
And unfortunately, they are not recognized as empty.
如何删除它们?
推荐答案
这样的事情应该可行:
$('p').each(function() {
if ($(this).text().trim().length == 0) {
$(this).remove()
}
});
这篇关于删除只包含空格的空元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文