Using:
var $a = $('.foo').find('.bar');
var $b = $('.bar', $('.foo'));
I know $b will have its context set to $('.foo'), while $a. Aside from that, I believe the two objects are the same, correct?
Follow up Qs:
- Will the perf be the same as well since the search is rooted off of the same object effectively?
- Does a more strict context improve perf in terms of core jquery operations at all? (I know it’s intended for plugin usage.)
Thanks!
EDIT:
yes, they are equivalent, here’s the source
To use context effectively, it needs to be an HTMLElement, otherwise the context is
documentfind()is implemented as such in jQuery 1.3.2find()uses the Sizzle selector engine to do the actual finding work (take a look at line 2364 in the jQuery source).and
pushStackisBrandon Aaron has written a great article on understanding the context in jQuery