AppendChild is mainly used to append the node and insert it to the end. During the loop, the length is changing due to non-stop moving. If you use for, the length at the beginning has been fixed, the problem is solved. appendChild is mainly used to append nodes and insert them to the end.
The Code is as follows:
Window. onload = function (){
Var ul2 = document. getElementById ('ul2 ');
Var oli = document. getElementsByTagName ('lil ');
For (var I = 0; I Ul2.appendChild (oli [I]);
}
}
The content with the lecture Id ul1 is inserted into ul2.
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.
The Code is as follows:
While (oli. length ){
Ul2.appendChild (oli [0]);
}
This is all about inserting the first entry, so it will be successful. You can try it.