我有一个div,我想删除该div中的所有HTML。
我该怎么做呢?
发布于 2009-03-17 03:18:42
您希望使用empty函数:
$('#mydiv').empty();
发布于 2009-03-17 10:39:40
我不认为empty()
或html()
是你要找的。我猜您正在寻找PHP中的strip_tags
之类的东西。如果你想这样做,那么你需要添加这个函数:
jQuery.fn.stripTags = function() {
return this.replaceWith( this.html().replace(/<\/?[^>]+>/gi, '') );
};
假设这是您的HTML:
<div id='foo'>This is <b>bold</b> and this is <i>italic</i>.</div>
然后你会这样做:
$("#foo").stripTags();
这将导致:
<div id='foo'>This is bold and this is italic.</div>
发布于 2009-03-17 06:03:11
另一种方法是将html设置为空字符串:
$('#mydiv').html('');
https://stackoverflow.com/questions/652917
复制相似问题