I got something like this which contains about 1000 dom elements
<table id="tableId">
<tr class="selected"><td>Text 1</td></tr>
<tr><td>Text 2</td></tr>
...
<tr><td>Text 500</td></tr>
</table>
problem is that i need to do something like this:
y = new selected tr;
$("#tableId").find("tr").removeClass("selected").eq(y).addClass("selected");
The problem here is the selector itself who takes about 600ms to process which is kinda too long for the things we are doing.
The machine im using uses a browser opera10 and has only 450Mhz running on linux!
Do you guys think that the problem comes from the machine being that slow?
Is there a way to improve the selector ?
I’ll tell you how to do it via programming logic:
by storing the currently selected element, you don’t need to loop over tons and tons of tr elements to find the selected one.
maybe an easier option for you would be to give the currently selected option an id of “currentlySelectedTr. id lookups are really optimized by web browsers.