Appendchild is mainly used to append a node and insert it to the end.
Window. onload = function (){
VaR ul2 = Document. getelementbyid ('ul2 ');
VaR Oli = Document. getelementbyid ('ul1'). Children;
For (VAR I = 0; I <Oli. length; I ++ ){
Ul2.appendchild (Oli [I]);
}
}
<H3> contents with the lecture ID ul1 are inserted into ul2 <Ul id = "ul1">
<Li> 1 </LI>
<Li> 2 </LI>
<Li> 3 </LI>
<Li> 4 </LI>
<Li> 5 </LI>
<Li> 6 </LI>
</Ul>
<Ul id = "ul2">
</Ul>
Insert the content of ul1 into ul2. This is actually a migration task, not a replication task.
You can check the effect.
Why is there such an effect? The reason is that the length is changing due to non-stop moving during the loop. If the for clause is used, the starting length has been fixed, so there is a problem.
While (Oli. Length ){
Ul2.appendchild (Oli [0]);
}
This is all about inserting the first entry, so it will be successful. You can try it.