In your specific example, your first example of
$('#something div.else');
gets optimized through Sizzle
(which is delivered within the jQuery lib) into
$('#something').find('div.else');
without that optimization, it would be slower, since the selector engine sizzle
does work from right to left. So, it would match all divs
with the class else
and would then check which of those has #something
as parent.
edit
The Sizzle optimazation
is slower
anyway, since it took a while until
that task is completed and some
functions are called on the way
In general, using jQuery functions
is a lot faster. For instance jQuerys .eq()
function will use an array slice
to reduce a wrappet set of jQuery objects, whereas :eq()
selector will invoke sizzle.
If in your example, div.else
elements are direct children of #something
, .children()
will beat .find()
since .find()
will also lookup all descendants (and their childs).