forum

Home / DeveloperSection / Forums / If I use object.getElementsByTagName(tagName) in a for statement

If I use object.getElementsByTagName(tagName) in a for statement

marcel ethan198212-Aug-2013

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.


Updated on 12-Aug-2013

Can you answer this question?


Answer

1 Answers

Liked By