On Jul 2, 2009, at 8:45 AM, north wrote:


Hi,

I just tested all my jQuery selectors using the jQuery Tester (http://
jquery.nodnod.net), and the results seem to "contradict" one thing I
read in a performance article: that you should descend from the
closest parent ID when using classes in your selector (the article
says "April 09", so the latest jQuery version was already available).

In my tests, using just the class selector (like span.myClass) was
always fastest (sometimes twice as fast as #myDiv span.myClass), and
this in all browsers I tested, not just the ones supporting
getElementsByClassName.

Maybe descending from the closest parent ID becomes a factor when you
have a lot of elements on you page? Any experiences?

Thanks

If the selectors aren't causing a discernible bottleneck, I wouldn't worry too much about optimizing them. Just out of curiosity, though, what happens if you do this:

$('#myDiv').find('span.myClass');

any faster?

Also, which browser are you testing?

--Karl

Reply via email to