On Feb 25, 8:24 am, morgancodes <hellomorganpack...@gmail.com> wrote:
> Hello,
> I'm trying to squeeze out every last bit of performance I can from
> IE6, and want to make sure there isn't a faster way than what I'm
> doing.
>
> I'm doing about 180 iterations of somethig like the following
>
> parentElem = $("parentTable");
> for(var i = 0; i<400; i++){
> $(tableRowHTML[i]).appendTo(parentElem)
>
> }
If speed really matters, forget jQuery methods. Presumably
'parentTable' is a reference to the table and tableRowHTML is an array
of HTML for the new table rows.
You can get a bit of a boost (20 to 30%) by not iterating and just
doing:
$(tableRowHTML.join('')).appendTo(parentElem);
However, that is still a sluggard, *the* fastest method (as in 100
times faster than either of the above in IE 6) is to use innerHTML
like:
var div = document.createElement('div');
div.innerHTML = '<table><tbody>' + sA.join('') + '</table>';
parentTable.appendChild(div.firstChild.tBodies[0]);
You can also just replace the current tbody with the new one if that
is required:
parentElem.replaceChild(div.firstChild.tBodies[0], parentElem.tBodies
[0]);
It will add 2,000 rows in less than 100ms (using pretty trivial 1 cell
row with a bit of text).
--
Rob