开发者

jquery multiple selector with a this

I see, from to time, this kind of jquery selector, which I don't really understand. What does this do in it:

开发者_开发技巧
$('.myClass', this).someFn();

Can someone explain to me, please?

Thanks


That searches for child elements with a class of myClass in the context of whatever this is and then calls someFn();

It would give you the same results as writing $(this).find(".myClass").someFn(); but is not as efficient.


This means that you are trying to select .myClass inside just this


The "this" keyword is something that is only meaningful inside a method of an object. It will mean something different -- or nothing at all -- depending on where you're calling this code from.

If you're calling it from inside an object (usually an HTML element), the object will be added to the selector that is passed to jQuery.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜