如何用空格删除元素? [英] How to remove elements with whitespace?
本文介绍了如何用空格删除元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以轻松删除没有空格的标签...
I can easily remove a tag that has no blank spaces...
$('h2:empty').remove();
但是,如果有空间...
But, when there is a space...
<h2> </h2>
...这不起作用.
我尝试过
if ($('h2').html() == " "){
$('h2').remove();
}
也没有运气.有人可以帮忙吗?
Also no luck. Can someone help with this?
推荐答案
尝试一下
$("h2").each(function(){
var self = $(this);
if ( self.html().trim().length == 0 )
{
self.remove();
}
});
这篇关于如何用空格删除元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文