是否可以执行$(this)
的相反操作?
因此,它不是获取 this
元素,而是获取与 .sb-popular-thumb a
匹配但不包括 $(this)
的所有内容?
请参阅下面的示例代码。我已用 $(reverse)
标记了 $(this)
,以便您可以看到我想要实现的目标。
$('.sb-popular-thumb a').hover(
function () {
$('.sb-popular').stop().animate({
height : '168px'
}, 200);
$(this).siblings('.sb-popular-thumb-title').show();
$(reverse).siblings('.sb-popular-thumb-overlay').stop().fadeIn(200);
},
function () {
$('.sb-popular').stop().animate({
height : '140px'
}, 200);
$(this).siblings('.sb-popular-thumb-title').hide();
$(reverse).siblings('.sb-popular-thumb-overlay').stop().fadeOut(200);
});
最佳答案
只需使用:
$('.sb-popular-thumb a').not(this)
.siblings('.sb-popular-thumb-overlay')
.stop()
.fadeIn(200);
它将获得所有 <a>
该类中除 this
之外的元素.
siblings()
会做几乎相同的事情,但只会获取兄弟元素(废话)?
关于jquery 与 $(this) 相反,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11720441/