开发者

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

开发者 https://www.devze.com 2023-03-31 20:55 出处:网络
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 l

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')


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


I'm pretty sure you can just use

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

精彩评论

暂无评论...
验证码 换一张
取 消