Yes, in fact the snippet you posted shows why $(context).find(selector) is
faster. $(selector,context) *calls* $(context).find(selector). By calling
$(context).find(selector) directly, you avoid this extra call and the checks
that lead to it. Therefore, $(context).find(selector) is faster by a very
small constant amount.

The improved readability is the more important point. $(selector,context) is
backwards from the normal parent-child order in CSS selectors, and it isn't
self-documenting the way $(context).find(selector) is.

There's no reason for $(selector,context) to exist at all, except for
backwards compatibility with jQuery code written in 2006. It should be
deprecated.

-Mike

On Sun, Oct 18, 2009 at 1:53 AM, MorningZ <morni...@gmail.com> wrote:

>
> Faster? aren't they just equivalent?
>
> according to the comments in the library file they are
>
> // HANDLE: $(expr, [context])
> // (which is just equivalent to: $(content).find(expr)
>        } else
> return jQuery( context ).find( selector );
>
> On Oct 18, 2:05 am, Michael Geary <m...@mg.to> wrote:
> > $('div',this) is simply a confusing way of writing $(this).find('div').
> The
> > only reason it exists at all is for "historical reasons": it was added to
> > jQuery before the .find() method existed.
> >
> > Never use $('div',this) in your code. Always use $(this).find('div')
> > instead. It is easier to read and faster too.
> >
> > -Mike
> >
> > On Tue, Sep 29, 2009 at 4:24 AM, runrunforest <craigco...@gmail.com>
> wrote:
> >
> > > Hi,
> >
> > > $('div', this)   what does that mean ?
>

Reply via email to