jquery 与 $(this) 相反

标签 jquery

是否可以执行$(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/

相关文章:

jquery - HTML/Jquery/Javascript 身份验证和授权模式 (ASP.NET)

javascript - JQuery 数据表 : How to add child row?

jquery - Bootstrap 2 修复了小型设备上的菜单问题

jquery - 为什么 Opera 扩展后台页面无法使用 cookie?

javascript - $(this) 正在提醒 jquery 中先前选择的值

jquery - jsddm显示在flot后面并变得透明

jquery - 如何在 Firefox 中检查元素的顶部、右侧、底部、左侧是否为自动

javascript - 带有ajax形式的谷歌recaptcha

javascript - Pinterest 分享 HTML 链接错误

javascript - 使用 1 个 Angular cookie 个性化页面