I need to display and manipulate, in a browser, a grid of up to 10,000 simple cells (say, 100 by 100). These cells are basically just a colored-in rectangle. Manipulations include changing cell colors using Javascript, handling a click on each cell, etc. Using 1 div per cell, and 1 div to wrap groups of cells into a row, I can get down to basically 10,000 DOM elements, but that is still quite a lot. I'm concerned about the performance of even the faster DOM functions, like getElementById
.
Initial question: if I store all the necessary DOM element references in a Javascript array (e.g. a 10,000-element array, one element for each cell) and manipulate the CSS on a per-element basis, does this have a prayer of being as quick as it would be when the DOM has, say, 200-500 elements?
So, I'm looking for suggestions of how I might be able to show this 100 x 100 grid more efficiently. I've considered using a canvas
and drawing each cell using Javascript, but I'm not sure how much faster this would actually be, especially when it comes time to edit the style of the cells. I'm also not so inclined to go with a canvas
because it's not fully cross-compatible (read: @#%$ing IE) and at some point I will probably need to make this thing IE-compatible.
What are your thoughts?