Original: JS Supplements: AppendChild Add mobile Node
Write JS for more than a year, has been thinking that they are very good, began to write a variety of blog posts to share, yesterday wrote a "talk about IE under the innerhtml caused problems" in the following comments, I found how ignorant.
So I went back to the next mdn,node.appendchild, which was made clear from the beginning,"If the node already exists, it is removed from the current parent node and then added to the new parent node." "
The simple point is to move the current node meaning, so yesterday's code to remove obox.innerhtml = ""; can be fully compatible.
Take a look at a common example:
var p = document.createelement ("P");d Ocument.body.appendChild (p);
This is the most common usage, creating a P-node that is added to the end of the body.
var p1 = document.getElementById ("p1");d Ocument.body.appendChild (p1);
The meaning of this code is to select the node with ID p1 and move to the end of the body.
Simply put, the node is placed at the end of the specified parent node, either new or selected.
However, InnerHTML in IE, there are real bugs, but I did not find the relevant article, I hope there will be a chance to solve the problem.
Through this question let me realize how ignorant I am, indeed should stop step, turn back supplements.