http://jarrin.net/jQuery_Selector_Performance

jQuery Selector Performance

Tuesday, May 12, 2009

I just got done spending a few hours debugging some slow jQuery and thought that I should share the summary of my findings with the world at large. Always try to use an id or class designation when selecting DOM elements. For example, on a page with about a megabyte of HTML I had this selector:

var firstRow = ("#aspxGrid table tr td table tr:first");

That one line took nearly eight seconds to execute. I poked around in the HTML a bit and was eventually able to change it to (approximately):

var firstRow = ("tr#_DXHeadersRow");

That line now executed in just one millisecond. Say it with me, "just one millisecond". I hope you've learned something today.

//Chronologically
< Previous: A Nice Day For Ducks <
> Next: DNS Change >
Add a Comment

Comments

your name
your email (optional)