简体   繁体   English

jQuery巨型菜单仅显示单击的父子菜单

[英]jQuery mega menu display only the clicked parent submenu

I have a simple Mega Menu. 我有一个简单的超级菜单。 I am trying to display the sub menu of the parent menu item clicked. 我正在尝试显示单击的父菜单项的子菜单。 But for some reason when I click the parent item all the sub menu's are displaying instead of the clicked parent item sub menu. 但是由于某种原因,当我单击父项时,所有子菜单都将显示,而不是单击父项子菜单。 What I am doing wrong. 我做错了。

Here is my JSFiddle link 这是我的JSFiddle链接

https://jsfiddle.net/jokcLjkb/4/ https://jsfiddle.net/jokcLjkb/4/

here is my js code. 这是我的js代码。

    $(document).ready(function() {
    $("a.drop").on('click', function(e) {   
        e.preventDefault();
        $("ul.mainNav li > .drop-full-col").css("display","block");
    });
});

Thanks and Appreciate it 谢谢并赞赏

Your line: 您的电话:

$("ul.mainNav li > .drop-full-col")

Will select all the submenus because you target the main nav and all the <div class="drop-full-col"> elements. 将选择所有子菜单,因为您定位到主导航和所有<div class="drop-full-col">元素。 You need to select only the ones relative to the link you click on, and to do that you need to use this to refer to the link being clicked on. 您只需要选择与您单击的链接相关的链接,然后使用this来引用被单击的链接。 So change: 所以改变:

$("ul.mainNav li > .drop-full-col").css("display","block");

to

$(this).closest('li').find(".drop-full-col").css("display", "block");

jsFiddle example jsFiddle示例

.closest('li') will look for the closest list item when you click the link, and .find(".drop-full-col") will then search down the DOM for the div you want. 单击链接时, .closest('li')将查找最接近的列表项,然后.find(".drop-full-col")将在DOM中搜索所需的div。

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

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