我正在编写一个需要在页面上移动包装节点元素的脚本。我发现当我这样做时,我删除了以前包裹的孩子。如何取消嵌套节点的子节点,以便可以将该父节点移动到其他地方?
我在想这样的事情:
var parg = document.getElementById("blah");
if (parg.hasChildNodes())
{
var children = parg.childNodes;
while (children.length > 0)
{
parg.insertBefore(parg.firstChild);
parg.removeChild(parg.firstChild);
};
};
我猜测的问题是“insertBefore”逻辑。