Reputation: 29
Here is the challenge; how can I iterate (+change the elements properties,while doing so) over table consisting more than 500 rows using jquery/Javascript? The added challenge is that the browser is IE8.
I tried using for loop and $.each over the table... I got the thing working, but its slowing down the damn IE and throwing script error(Error: Do you want to continue this script? It may slow down your computer..bla bla bla).
The problem is not to know how to iterate and change the properties of individual columns, but how to optimize this process.
Any help is much appreciated.
Upvotes: 0
Views: 1161
Reputation: 23406
In general, if you're executing a time-critical task, don't use jQuery. Every $('.classname')
executes at least 20 jQuery lines, and especially in case of IE8, also a ton of native iterating through the document.
There's a limit for script lines executed in IE8. By default it executes one million lines, then user is asked, if he wants to continue the script. This limit is controlled by registry, but in case of a web app, it's not usefull to increase the value ofcourse.
In IE8 rendering speed is also an issue.
innerHTML
/ innerText
, use createElement()
and/or createTextNode()
and appendChild()
and/or insertBefore()
instead.getElementsBy/Tag/Class/Name()
.table.rows
and table.rows[n].cells
collections where ever possible.Upvotes: 2
Reputation: 6156
Have u tried this
var table = document.getElementById("mytab1");
for (var i = 0, row; row = table.rows[i]; i++) {
//iterate through rows
//rows would be accessed using the "row" variable assigned in the for loop
for (var j = 0, col; col = row.cells[j]; j++) {
//iterate through columns
//columns would be accessed using the "col" variable assigned in the for loop
}
}
Upvotes: 1