I came across a little issue with JS in my project.
Basically I use this type of for loop for most arrays:
for (var item in array)
{
// Do something with each "item"
}
Now that is working fine and dandy for the most part, but when I use it like this:
for (var element in someDOMelements)
{
element.AddEventListener(...);
}
It is going to throw me an error, saying AddEventListener is not working However if I adjust the code to something like:
for (var i = 0; i < someDOMelements.length; i++)
{
someDOMelements[i].AddEventListener(...);
}
It's working as it should. And just to rule it out I logged the array that the DOM elements are in before the loop and it correclty gave me a list (HTML Collection) of all the objects..
Is there anything specific going on here, that prevents me from manipulating DOM elements with these kind of for loops?
Cheers!