tags:

views:

31

answers:

3

I feel like $('.selector', myContext) and myContext.find('.selector') are two identical ways to get the same information. Is there a practical reason when you would use one over the other? Speed perhaps?

+5  A: 

$('.selector', myContext) and $(myContext).find('.selector') are completely equivalent:

From the jQuery 1.4.2 source (core.js):

//...

// HANDLE: $(expr, context)
// (which is just equivalent to: $(context).find(expr)
} else {
    return jQuery( context ).find( selector );
}

//...
CMS
I do remember a blog post or something, probably from John Resig, that deprecates the "context" second-parameter style.
Pointy
thanks for this answer
Jason
+1  A: 

The first involves slightly less characters of code, but other than that the same thing

Joey C.
+2  A: 

Internally, selector context is implemented with the .find() method, so $('span', this) is equivalent to $(this).find('span').

From: http://api.jquery.com/jQuery/#jQuery1

TomWilsonFL
thanks, appreciate it
Jason