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.
精彩评论