If I use object.getElementsByTagName(tagName) in a for statement,
for (index = 0; index < object.getElementsByTagName(tagName).length; index++) {
object.getElementsByTagName(tagName)[index].property = value;
}
Does the browser instantiate a new nodeList object for every pass through the loop, or does thebrowser simply refer to a single generated list every time, or maybe it instantiates a list, references the object specified and unloads the list object every pass through the loop?
I've been wondering if its better to store the nodeList object to a variable and reference it when neened.
Pravesh Singh
12-Aug-2013Your browser is generating a new list each time. But this code will work as index is changing every run.
It is a good practice to first save node list in some var: