How to corectly iterate through getElementsByClassName

bloutix

New Member
I am Javascript beginner.I am initing web page via the \[code\]window.onload\[/code\], I have to find bunch of elements by their class name (\[code\]slide\[/code\]) and redistribute them into different nodes based on some logic. I have function \[code\]Distribute(element)\[/code\] which takes an element as input and does the distribution. I want to do something like this (as outlined for example here or here):\[code\]var slides = getElementsByClassName("slide");for(var i = 0; i < slides.length; i++){ Distribute(slides);}\[/code\]however this does not do the magic for me, because \[code\]getElementByClassName\[/code\] does not actually return array, but a \[code\]NodeList\[/code\], which is... ...this is my speculation......being changed inside function \[code\]Distribute\[/code\] (the DOM tree is being changed inside this function, and cloning of certain nodes happen). \[code\]For-each\[/code\] loop structure does not help either.The variable slides act's really un-deterministicaly, through every iteration it changes it's length and order of elements wildly.What is the correct way to iterate through NodeList in my case? I was thinking about filling some temporary array, but am not sure how to do that...
 
Top