I'm having trouble with a while loop in my code. For some reason, it is looping endlessly. The code is this:
function transf(){
var container = document.getElementById('container');
var compartimento = document.getElementById('compartimento');
while (compartimento.childNodes.length > 0) {
container.appendChild(compartimento.childNodes[0]);
}
var alturadocontainer = container.clientHeight;
var containerlc = container.lastChild;
var container2 = document.getElementById("container2");
while (alturadocontainer > 100){
container2.insertBefore(containerlc, container2.childNodes[0]);
}
}
The first while loop works without problems. The problem is in the second. The expected result is that as long as the height of the container is greater than 100, the last elements of the container pass to container2 (which, in theory, should decrease the height of the container, but apparently this is not happening, infinite loop). Why is this happening?