I have a for loop that runs through a set of elements, removing the 'selected' class from each. However, it skips over every second iteration. I've found that I can get around this by adding j--, which I guess is fine except for lengthening my code. But I wonder if someone could explain why it skips and perhaps suggest a more succinct way of writing this code? (I'm still learning the ropes and want to make sure I understand what's going on.)
var selections = document.getElementsByClassName(name + 'selected');
for (var j = 0; j < selections.length; j++) {
selections[j].classList.remove('selected');
j--; // the fix
}
// where name is a present variable
Thanks for your time!