javascript - 在父 jQuery 中查找特定类的下一个元素

标签 javascript jquery

我有以下内容:

<div class="container">
Test 1
<div class="child">Testing</div>
</div>

<div class="container">
Test 2
<div class="child">Testing</div>
</div>

<div class="container">
Test 3
<div class="child">Testing</div>
</div>

我希望在鼠标离开容器时将鼠标悬停在容器内的子 div 显示和隐藏。

我目前有:

        $('.container').hover(
            function () {
                $(this).next('.child').show();
            },
            function () {
                $(this).next('.child').hide();
            }
        );

不过好像不行。 任何建议表示赞赏,谢谢。

最佳答案

next() 用于 sibling ,您应该为 child 使用 children :)...

 $('.container').hover(
        function () {
            $(this).children('.child').show();
        },
        function () {
            $(this).children('.child').hide();
        }
    );

关于javascript - 在父 jQuery 中查找特定类的下一个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3186670/

相关文章:

javascript - 闭包中的变量

Javascript/谷歌地图 - 无法删除标记

javascript - Android Emulator 浏览器是否适合并可靠地测试 HTML/Javascript 应用程序?

javascript - 当被溢出的父元素隐藏时,防止使用 Tab 键进行链接 :hidden

javascript - jQuery animate() 扩展 DIV

jquery - 文档选择器和窗口选择器有什么区别?

javascript - jquery 将 div 元素可见性检测为 true,即使不可见

jquery - 如何同步两个嵌套的jquery foreach循环?

javascript - 仅对 Chart.JS 进行一次动画处理

javascript - Angular 获取请求