Jorge
Jorge

Reputation: 18257

Is $('selector', element) the same as element.find('selector')?

I was looking this post about best practices of jquery jquery-pitfalls-to-avoid in one of the answers someone said about the good uses of context in a selector and quotes a examples like this

var ct = $('#container');
$('.myClass',ct)

With the finally to explain that this will find in the context of the container and not in all the document. Now my question if that code is not the same that this function

var ct = $('#container');
ct.find('.myClass')

Upvotes: 0

Views: 117

Answers (2)

Overload119
Overload119

Reputation: 5396

I'm pretty sure you can just use

var ct = $('#container .myClass');

Upvotes: 0

shesek
shesek

Reputation: 4682

It is exactly the same. In fact, the first version delegates to the second (making the second slightly faster).

Upvotes: 4

Related Questions