I\'m performing a small text with JavaScript with the getElementsByClassName() and I am getting some unwanted results. I would like the script to change each CS
document.getElementsByClassName returns a HTMLCollection object, which is live
An HTMLCollection in the HTML DOM is live; it is automatically updated when the underlying document is changed.
So when you call
blockSet[0].className = "block-selected";
You changed the underlying document and that item is not in the collection anymore (the blockSet[0] is now the second item in your original selection).