In the past and with most my current projects I tend to use a for loop like this:
var elements = document.getElementsByTagName(\'div\'); for (var i=0; i
I too advise to use the simple way (KISS !-)
-- but some optimization could be found, namely not to test the length of an array more than once:
var elements = document.getElementsByTagName('div'); for (var i=0, im=elements.length; im>i; i++) { doSomething(elements[i]); }