I am trying to run a while loop to remove all the elements of a particular class name from the DOM as given in the answer here. For some reason, I am getting an error.
Uncaught SyntaxError: Invalid or unexpected token
The code I am trying to run is lengthy but the basic idea is identical to the above-linked answer.
function resetGame() {
var cardColumns = document.getElementsByClassName('card-column');
while (cardColumns[0]) {
cardColumns[0].parentNode.removeChild(cardColumns[0]);
}
}
When I hover over the error (which shows at the end of the loops curly brace) it shows \u200b
in Chrome Inspect.
I have tried changing the class name, and even directly copy-pasting the guy above answer. Same error. When I paste the loop into the console on its own I get the same thing, so my best assumption is I have something incorrect fundamentally with the syntax, not the rest of my code.
Any ideas?