+ 1
while-loop problem
Hey Guys, I have a problem with the following code: var x = document.getElementById('Auswahl').value; var activeElements = document.querySelectorAll('#class1').length; while(activeElements < x){ document.getElementsByClassName("wrapper")[0].appendChild(cln); activeElements = document.querySelectorAll('#class1').length; if(activeElements == x){ break; } } In this loop my input is 3. The loop should run until i have 3 Elements named #class1. But the loop never stops. It works with the input 2 but not with 3 or 4. Can anybody help me out?
6 Respostas
0
@Rithea Sreng after some debbuging i found out that this line "document.getElementsByClassName("wrapper")[0].appendChild(cln);" is only executet 1 time, After that this line does not work anymore. at the beginning i have tried it with activeElements++ but it didn't work.
0
NVM I found the problem
0
How did you solve it?
0
document.getElementsByClassName("wrapper")[0].appendChild(cln);
This line is like Strg+V but only works one time. So i put two code lines (which are not included in the code above) into the while loop and then i could copy it infinite times.