我对如何追踪作为父元素在树上的元素有点困惑。
$('.btn-action').hover(
function(){
$(this).find('.product-card').addClass('animated bounce');
},
function(){
$(this).find('.product-card').removeClass('animated bounce')
}
);
.product-card
类不是直接父类,而是树的更上层。我需要根据 .btn-action
类上的悬停方法对其进行动画处理。这可以通过 .parent()
或 .find()
来实现吗?
最佳答案
要进入树,您可以使用 .closest()。
$(this).closest('.product-card').addClass('animated bounce');
要在树中进一步查找,请使用 .find()。 要保持同一水平,您可以使用 .siblings()
虽然我不确定你的类名中的空格。如果不打算使用多个类,请尝试使用破折号。
关于javascript - 在jquery中查找远方 parent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45246077/