简体   繁体   English

根据一个子jquery分别隐藏下拉菜单

[英]individually hiding drop-downs according to one child-jquery

So I've painfully got multiple drop-downs toggling states(hidden and shown) in JQuery but I have some code which tells the side bar which page is active and gives it the style active and I would like a drop down to not be hidden if there is a child active in it. 所以我很痛苦地在JQuery中有多个下拉菜单来切换状态(隐藏和显示),但是我有一些代码告诉侧边栏哪个页面是活动的,并给它激活样式,我希望下拉菜单不被隐藏如果其中有一个活跃的孩子。

The top level link which you click to view the drop-down gets given the id "HAC"(has active child) if it has an active child but I think I might be burning my brain out on this. 如果单击它以查看下拉列表的顶级链接,则其ID为“ HAC”(具有活跃的孩子),如果它有一个活跃的孩子,但我想我可能会为此而绞尽脑汁。

Here's a jsfiddle page with the working demo of the problem. 这是一个jsfiddle页面,其中包含问题的工作演示。

the drop down is set out like this in a nav 下拉菜单在导航中这样设置

<ul id="HAC" class='topLevel'>                
   <li class='subItem'>
       <a class="active" href='thatpage.php'>That page</a>
   </li>
   <li class='subItem'>
       <a href='thatotherpage.php'>That other page</a>
   </li>
</ul>

thanks in advance for any help 预先感谢您的任何帮助

I think what you are looking for is the jQuery :not selector . 我认为您正在寻找的是jQuery:not选择器 Here is an update to your fiddle 这是您的小提琴的更新

function dropDowns() {
    //for each toplevel li a
    $(".topLevel:not(#HAC) li a").each(function() {
        //hide subitems if not HAC (has active children)
            $(this).hide();
    });
    //Toggle show them on click
    clickToggle();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM