views:

38

answers:

3

In Paul Irish's blog http://paulirish.com/2009/perf/, in slide 30 it is mentioned:

$('#container').find('div.robotarm') is faster than $('#container div.robotarm')

What's your opinion?

+1  A: 

Maybe in an earlier version of jQuery that was the case. However, the expression

$('#container div.robotarm')

is normalized through jQuery into

$('#container').find('div.robotarm')

So the only reason why $('#container div.robotarm') should be slower is because of function call overhead. But, that would really be a trivial difference.

If that call wasn't normalized, sizzle (Resigs css selector engine) would be used to lookup that element (right to left). That of course would be much slower.

jAndy
+2  A: 

Since you asked for opinion, it doesn't matter.

You can always come up with a case where one runs faster than the other in some browser under a certain configuration of the DOM. No need to split hairs.

Anurag
+2  A: 

Benchmark test: http://jsperf.com/find-vs-descendant-selector

PetersenDidIt