Blog Stats
  • Posts - 19
  • Articles - 0
  • Comments - 3
  • Trackbacks - 19

 

Thursday, March 02, 2006

JavaScript Performance: Fast DOM Iterator

After numerous tests, this function provides the most performant way to iterate over all the elements in the DOM:

function walkTheDom() {

      var items = document.getElementsByTagName("*");

      var i=items.length;

      var item;

      do

      {

        item = items[i];

        //Do something with item

      }

      while (--i);

}

 

 

 

Copyright © Michael Parsons