1th: First appendchild The value returned when inserting the node is the inserted node itself, and the parent node that you want to insert must also be found:
1 var returnnode = parentnode.appendchild (childnode); 2 Console.log (Returnnote===childnode); // true
2nd: AppendChild The new node to be inserted if it exists in the flow of the document, then the heart node is not copied and then inserted under the parent node, but instead, the new node is moved from the source document stream to the parent node to be inserted:
1 <DivID= "Test">2 <Div>Adscasdjk</Div>3 <DivID= "a">Adscasdjk</Div>4 </Div>5 <Scripttype= "Text/javascript">6 varT=document.getElementById ("Test");7 vara=document.getElementById ('a');8 //var tt = A.clonenode (true);9 T.appendchild (a);Ten </Script>
This has the JS code and no JS code performance is the same, but in the firebug can be clearly found that the ID of the div moved to the no ID of the div before, that is, id= ' a ' div just moved to the parent node.
1 <DivID= "Test">2 <Div>Adscasdjk</Div>3 <DivID= "a">Adscasdjk</Div>4 </Div>5 <Scripttype= "Text/javascript">6 varT=document.getElementById ("Test");7 vara=document.getElementById ('a');8 varTT=A.clonenode (true);9 t.appendchild (TT);Ten </Script>
The solution is to clone the node you want to insert into the appropriate location so that you can achieve the desired effect.
AppendChild () Issues to be aware of when inserting nodes