I am currently trying to optimize a function I have and am looking to select both $(this)
as well as $(#selector)
or varName
I have listed my code below to show an example, 开发者_如何学运维I have done some searching and cannot find anything specific.
$(varName, this).stop().animate({opacity : 1}, 'slow');
All help appreciated.
If you pass a second parameter to $()
, then jQuery will treat it as a context to search in. What you need is to build up a jQuery object using the .add()
method as show below:
$("#selector").add(this).add(varName).stop().animate({opacity : 1}, 'slow');
Try this it may solves your problem.
$("#selector").add(this).add(varName).stop(true).animate({opacity : 1}, 'slow');
Try changing to:
$(varName, this).stop(true).animate({opacity : 1}, 'slow');
Assuming varName
is something like $('#foo')
...
$(this).add(varName).stop().animate({opacity : 1}, 'slow');
精彩评论