jQuery选择下一个div [英] jQuery select next div
本文介绍了jQuery选择下一个div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以代码如下所示:
当鼠标悬停在当前link1上时如何更改div1?
so code looks like this: How can I change div1 when hovering over current link1 ?
<ul>
<li>
<a class='link1'></a>
<a class='link2'>
<div class='div1'></div>
<div class='div2'></div>
</a>
</li>
<li>
<a class='link1'></a>
<a class='link2'>
<div class='div1'></div>
<div class='div2'></div>
</a>
</li>
</ul>
我试过这样:
$(".link1").hover(
function () {
$(this).nextAll('.div1').css('display','block');
...
},
function () {
...
}
);
推荐答案
.next
和 .nextAll
只搜索直接兄弟姐妹。你想要的元素是链接兄弟的孩子。
.next
and .nextAll
only search the "direct siblings". The element you want is a child of the link's sibling.
你可以试试这个:
$(this).next('.link2').children('.div1')
或者,您可以前往父母并搜索所有后代:
Or, you can travese to the parent and search all decendants:
$(this).parent().find('.div1')
这篇关于jQuery选择下一个div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文