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!)

Javascript optimisation - while (See related posts)

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.

You need to create an account or log in to post comments to this site.

Related Posts