javascript - 选择 LI 元素中的嵌套 div

标签 javascript jquery html

我尝试在单击 LI 时使用 jQuery 选择包含在 LI 元素中的 div,这是我到目前为止的代码。

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

HTML

<nav id="about-nav">
    <ul>
        <li class="about-nav-item">
            <a href="#">Story</a>

            <div class="white-content">TEST</div>

        </li>
        <li class="about-nav-item">
            <a href="#">Approach</a>

            <div class="white-content">TEST1</div>

        </li>
        <li class="about-nav-item">
            <a href="#">Team</a>
        </li>
        <li class="about-nav-item">
            <a href="#">Network</a>
        </li>
    </ul>
</nav>

CSS:

.white-content {
    width: 220%;
    float: left;
    margin-left: 95%;
    top: -20px;
    position: absolute;
    background: white;
    min-height: 350px;
    color: black;
    display: none;
}

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

最佳答案

您需要使用.children().find().about-nav-item 起就在这里是 .white-content 的父级分区:

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

<强> Fiddle Demo

关于javascript - 选择 LI 元素中的嵌套 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23547774/

相关文章:

javascript - 在 android 中引用 javax.script.ScriptEngine 或评估 javascript 表达式

JQuery 测量隐藏元素的位置

javascript - 类似github的浏览器前进/后退滑动页面效果

jquery html() 函数在整个页面而不是在 div 中显示内容

javascript - iOS 8 Safari 打印重定向不会停止 javascript 执行

javascript - jquery/JS 动态控件的简单数据绑定(bind)

javascript - 以 Angular 加载测试图像源时出错

javascript - files.length 在 Internet Explorer 中未定义

javascript - javascript window.stop() 的反义词是什么

javascript - Instagram API : Retrieve IDs/names of friends who have liked the user's posted Instagram images