javascript - jquery 在相对于 'This' 的多个元素上运行相同的函数

标签 javascript jquery jquery-selectors

$(".column a").mouseenter(function() {
var color_column=$(this).closest('.column').children('.coloured-strip').css('color');

$(this).siblings('p').animate({color:color_column},2000);
$(this).animate({color:color_column},2000);
});

有什么方法可以将两个动画函数合并为一个,因为它们是相同的?

谢谢 卢卡

最佳答案

当然,只需使用 .add() :

$(this).siblings('p').add(this).animate({color:color_column},2000);

关于javascript - jquery 在相对于 'This' 的多个元素上运行相同的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7370303/

相关文章:

php - 将超链接元素传递到超链接页面并在超链接页面接收该元素

javascript - 如何在输入标签上用空格替换逗号?

javascript - 使用 jQuery 更新按钮上的数据属性

c# - 在 ListView 中显示/隐藏 Div

javascript - react 不变违规 : Objects are not valid as a React child

jquery - 如果 AJAX 请求被不同链接的用户中断,如何跳过 'getJSON' 错误处理

javascript - 提交前更改表单属性

javascript - 获取给定元素和类的特定元素

jquery - 是否可以在 jQuery 选择器中使用多个属性?

javascript - 对象数组内的数组上的 Angular ng-repeat