I'm trying to remove all the elements of the class cupcake
from my dom
to repaint them based on a filter.
I'm doing;
let cupcakes= document.getElementsByClassName("cupcake");
alert(cupcakes.length);
for(element of cupcakes){
console.log(element);
container.removeChild(element);
console.log(element);
console.log("-------------------------------------------------------");
}
The length of elements that I recover is exactly what I need and the elements as well, but I do not understand that I only delete the odd ones, the output of the previous code is as follows;
Only shows the odd elements Why? I need to delete all of them, each one of those that the loop goes through, if I delete the line of removeChild
it prints all the objects.