appendChild in IE6/IE7 does not work with existing elements

社会主义新天地 提交于 2019-12-24 15:27:25

问题


I have a div that needs to be moved from one place to another in the DOM. So at the moment I am doing it like so:

flex.utils.get('oPopup_About').appendChild(flex.utils.get('oUpdater_About'));

But, IE, being, well, IE, it doesn't work. It works all other browsers, just not in IE.

I need to do it this way as the element (div) 'oUpdater_About' needs to be reused as it is populated over and over.

So i just need to be able to move the div around the DOM, appendChild will let this happen in all browsers, but, IE.

Thanks in advance!


回答1:


You have to remove the node first, before you can append it anywhere else. One node cannot be at two places at the same time.

var node = flex.utils.get('oUpdater_About')
node.parentNode.removeChild(node);
flex.utils.get('oPopup_About').appendChild(node);



回答2:


make sure to clone the oUpdater_About (with node.cloneNode(true)) this way you get a copy and can reuse the dom-snippet as often as you want (in any browser)




回答3:


This post tends to suggest that there is indeed a problem with appendChild with respect to this:

http://metadeveloper.blogspot.com/2007/01/ie-7-appendchild-bug.html

Have you tried cloning it, removing it, then inserting the clone instead?

James



来源:https://stackoverflow.com/questions/1232410/appendchild-in-ie6-ie7-does-not-work-with-existing-elements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!