开发者

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().

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜