Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

« Newer Snippets
Older Snippets »
1 total  XML / RSS feed 

Javascript optimisation - while

Using as a benchmark the task of iterating over a live collection produced by getElementsByTagName. IE/Win, Gecko and Safari all agree as to the fastest means:

var i = 0, el, els = document.getElementsByTagName(nodeName);
while (el = els[i++]) {
    // [...]
}


Using a while loop and storing the live collection in a variable is the quickest technique in all of these browsers.
« Newer Snippets
Older Snippets »
1 total  XML / RSS feed