Suppose I call getElementsByClassName() and store the result in a variable like so:
var editButtons = document.getElementsByClassName("editButtonDisabled");
Then I iterate through that variable (which is a nodelist, so .item(i)
is used and not [i]
) and change the class name of each item:
for (var i = 0; i < editButtons.length; i++) {
var editButton = editButtons.item(i);
editButton.className = "editButtonEnabled";
}
For some reason the loop skips over all the odd-indexed members of editButtons
and only applies the class name change to the even-numbered ones, as though the length of editButtons
is being mutated by changing the properties of its members, which shouldn't be the expected behavior in my opinion.
I know I can get around this by just throwing all the elements into an array first and then looping through it again, but that requires writing two loops when only one should be necessary, and I'm curious as to why it's doing this in the first place.