javascript - 寻找姐妹元素

标签 javascript jquery

<div class="videoItem">
    <div class="innerVideoItem">
         <a><div class="overlayBg"></div></a>
         <a><img class="overlayPlay"><img></a>
    </div>
</div>
<script>
    $(".overlayPlay").hover(function(){
          // How do I find overlayBg here?
    });
</script>

如何在不使用 $(".overlayBg") 的情况下访问 .overlayBg?

最佳答案

在您的标记中,overlayBgoverlayPlay 不是 sibling ,它们是表兄弟,您可以使用 closestfind > 方法。

$(".overlayPlay").hover(function(){
    $(this).closest('.innerVideoItem').find('.overlayBg');
    // $(this).parent().prev().find('.overlayBg')
});

关于javascript - 寻找姐妹元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14189601/

相关文章:

javascript - 从 JSON 嵌套数组中检索内容

javascript - 我的内容在媒体查询中漂浮在容器后面

javascript - 在客户端临时存储 xml 的最佳方法是什么?

jquery - 尝试使用 OR 逻辑将同位素过滤器与分页集成

javascript - 如何获取 contenteditable div 中当前正在编辑的节点的索引

jquery - 下拉菜单栏对齐问题

For 循环中的 Javascript If 语句适用于 Chrome 和 Safari,但不适用于 Firefox

javascript - 带有表格和图像的 JQuery slider

javascript - onclick:改变位置后做一些事情

javascript - TypeScript 中泛型的行为