开发者

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


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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜