Javascript 选择LI元素中的嵌套div

Javascript 选择LI元素中的嵌套div,javascript,jquery,html,Javascript,Jquery,Html,当单击LI时,我试图使用jQuery选择LI元素中包含的div,下面是我到目前为止的代码 jQuery( ".about-nav-item" ).click(function() { jQuery(this).next('.white-content').show(); }); HTML 问题是,单击元素时,它什么也不做,也不显示元素。您需要在此处使用.children()或.find(),因为。关于导航项是的父项。白色内容div: jQuery( ".about-nav-item"

当单击
LI
时,我试图使用jQuery选择
LI
元素中包含的div,下面是我到目前为止的代码

jQuery( ".about-nav-item" ).click(function() {
    jQuery(this).next('.white-content').show();
});
HTML


问题是,单击元素时,它什么也不做,也不显示元素。

您需要在此处使用
.children()
.find()
,因为
。关于导航项
的父项。白色内容
div:

jQuery( ".about-nav-item" ).click(function() {
    jQuery(this).find('.white-content').show(); // or jQuery(this).children('.white-content').show();
});

您需要在此处使用
.children()
.find()
,因为
.about nav item
的父项。白色内容
div:

jQuery( ".about-nav-item" ).click(function() {
    jQuery(this).find('.white-content').show(); // or jQuery(this).children('.white-content').show();
});

您可以使用
find()
执行此操作:

jQuery(".about-nav-item").click(function() {
    jQuery(this).find('.white-content').show();
});
或上下文选择器:

jQuery(".about-nav-item").click(function() {
    jQuery('.white-content', this).show();
});
您可以使用
find()
执行此操作:

jQuery(".about-nav-item").click(function() {
    jQuery(this).find('.white-content').show();
});
或上下文选择器:

jQuery(".about-nav-item").click(function() {
    jQuery('.white-content', this).show();
});

点击@Felix。fyi@James,
.next()
在dom树中横向移动,相当于本机javascript
.nextSibling
属性
.find()
将使用本例中的
jQuery(this)
作为根遍历dom树的每个节点
.children(…selector…
会将元素的直接子元素筛选到与“selector”匹配的子元素。在find和children的情况下,您应该期望在某些情况下,结果将包含@Felix上的一组元素(例如,可能有多个)。fyi@James,
.next()
在dom树中横向移动,相当于本机javascript
.nextSibling
属性
.find()
将使用本例中的
jQuery(this)
作为根遍历dom树的每个节点
.children(…selector…
会将元素的直接子元素筛选到与“selector”匹配的子元素。对于find和children,您应该期望在某些情况下,结果将包含一组元素(例如,可能有多个元素)