jquery running same function on multiple elements relatives to 'This'
$(".column a").mouseenter(function() {
var color_column=$(this).closest('.column').children('.coloured-strip').css('color');
$(this).siblings('p').animate({color:color_column},2000);
$(this).an开发者_高级运维imate({color:color_column},2000);
});
There's any way I can group the two animate functions into one since they're identical?
thanks luca
Sure, just use .add()
:
$(this).siblings('p').add(this).animate({color:color_column},2000);
You can use the andSelf()
method:
$(this).siblings('p').andSelf().animate({color:color_column},2000);
Instead of:
$(this).siblings('p').animate({color:color_column},2000);
$(this).animate({color:color_column},2000);
You can do:
$(this).siblings('p').add(this).animate({color:color_column},2000);
See the documentation for .add()
.
精彩评论