Strange behavior when iterating over HTMLCollection from getElementsByClassName
问题 I wrote a function to change the class of elements to change their properties. For some reason, only some of the elements have changed. It took me a few hours to find a solution, but it seems odd to me. Perhaps you can explain this to me. This isn’t working: function replace(){ var elements = document.getElementsByClassName(\'classOne\'); for (var i = 0; i < elements.length; i++) { elements[i].className = \'classTwo\'; } } See the JSFiddle: only every second item is affected; only every