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?
views:
31answers:
3
+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
2010-06-23 23:13:59
I do remember a blog post or something, probably from John Resig, that deprecates the "context" second-parameter style.
Pointy
2010-06-23 23:14:58
thanks for this answer
Jason
2010-06-23 23:37:33
+1
A:
The first involves slightly less characters of code, but other than that the same thing
Joey C.
2010-06-23 23:15:19
+2
A:
Internally, selector context is implemented with the .find() method, so $('span', this) is equivalent to $(this).find('span').
TomWilsonFL
2010-06-23 23:16:08