htmlcollection

Strange behavior when iterating over HTMLCollection from getElementsByClassName

吃可爱长大的小学妹 提交于 2019-11-26 09:51:12
问题 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

console.log of element.children shows 0 length but has three entries when expanded later

落花浮王杯 提交于 2019-11-25 22:48:49
问题 In my javascript, I have two elements. I have logged the two elements and it shows... Element 1. Element 2. There are problem. When I console.log the element s .children they obviously return some HtmlCollection s You will understand what the following means in a minute: But the weird thing is, that one HtmlCollection is empty (and has a length of 0), but has 3 elements (and has a length of 3). If you read the console.log s below for the children of the elements, you will understand what I am