appendChild is mainly used to append nodes to the end
window. onload = function(){
var ul2 = document.getElementById('ul2');
var oli = document.getElementsByTagName('li');
for(var i=0;i
ul2.appendChild(oli[i]);
}
}
Insert the content with Id ul1 into ul2
Insert the content of ul1 into ul2. This is actually moving rather than copying. Remember
You can check the effect
Why This effect occurs because the length is changed due to constant moving during the loop. If you use for, the starting length has been fixed, so there is a problem, so it needs to be changed to
while(oli.length){
ul2.appendChild(oli[0]);
}
This is because the first one is inserted, so it is successful. You can try it.