我有以下内容:
<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/