DOM manipulation while looping
Filed Under (Others) by admin on 06-07-2009
Document Object Model or DOM for short, is just a fancy term for “everything on your website”. It includes every table, image, link, form field, etc. on your page ALL HTMP ELEMENTS. JavaScript enables us to manipulate any element on the page in real time.
I will show in this example how to manipulate DOM elements faster inside the loop, making elements display fast on the page. Â You only need a firebug console to try it.
First: The tradional way of manipulating DOM elements inside a loop
var tdelem=”";
console.time(‘oldloop’);
for (i=0;i<=1000;i++){
tdelem = “#div” + i;
$(tdelem).html(‘hello’);
$(tdelem).css(‘color’,'red’);
}
console.timeEnd(‘oldloop’);


