I have several DOM elements in my html with the class "high", I want to get all elements with the "high" class and remove the class from it, I have tried this already (I am using Chrome's console to test the code):
var check= document.getElementsByClassName("high");
for(var k = 0; k < check.length; k++){
check[k].classList.remove("high");
}
But the problem is that it seems to only remove the class from half the elements in the array and stop. If I do console.log(check);
afterwards I can see that the array has had half its elements removed. How ever, this seems to work:
var check= document.getElementsByClassName("high");
while(check.length > 0){
check[0].classList.remove("high");
}
I would expect the first code to work, but now that the second one is working, I don't know exactly how and why this happens.
SOLVED
The Question was answered, but for those interested in seeing this problem in action: