删除div节点的子节点 [英] Deleting child nodes of a div node
本文介绍了删除div节点的子节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码来删除div节点的子节点.这两个代码都正确吗?
I have following codes to remove child nodes of a div node. Are both of these codes correct?
while(innerWindowContentBox.hasChildNodes())
innerWindowContentBox.removeChild(innerWindowContentBox.childNodes[0]);
其他是
innerWindowContentBox.innerHTML = '';
请注意,该代码用于Greasemonkey脚本,因此不需要IE支持.
Note that the code is for a Greasemonkey script so IE support is not required.
推荐答案
Added another test case to the jsPerf benchmark posted by @Brock Adams. It is slightly faster to test using element.firstChild
(at least in Chrome):
while (containerNode.firstChild ) {
containerNode.removeChild (containerNode.childNodes[0] );
}
这篇关于删除div节点的子节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文