简体   繁体   English

打开和关闭导航菜单并在单击时关闭其他导航菜单

[英]Toggle Nav Menu on and off and close other nav menus on click

I have tried several different venues and ultimately came back to this which allows me to toggle them on and off individually but also I can open one dropdown and then also open another dropdown without the first closing.我尝试了几个不同的场所,最终又回到了这一点,这允许我单独打开和关闭它们,但我也可以打开一个下拉菜单,然后打开另一个下拉菜单,而无需第一次关闭。 I want to be able to toggle them on and off as well as close all others when one is toggled on.我希望能够打开和关闭它们,并在打开时关闭所有其他的。

$('.list > li a').click(function () {
    $(this).parent().find('ul').toggle();
});

Try this. 尝试这个。 Basically hide all toggles first and then show which is clicked. 基本上先隐藏所有切换开关,然后再显示被单击的开关。 Note. 注意。 I have removed the a tag and took the click on to the li element itself. 我已经删除了一个标签,并点击了li元素本身。

$('.list > li').click(function () {
    $('.list  li').hide();
    $(this).find('ul').toggle();
});

Suggestion: Please share your html and jsfiddle link to get a better answer. 建议:请分享您的html和jsfiddle链接以获得更好的答案。

you can hide all other elements first and then toggle current element. 您可以先隐藏所有其他元素,然后再切换当前元素。

$('.list > li a').click(function () {
    $('.list > li a').not(this).parent().find('ul').hide();
    $(this).parent().find('ul').toggle();
});

I want to close the first nav dropdown when we open any other drop down currently I am using the elementor navbar.当我们打开当前我正在使用元素或导航栏的任何其他下拉菜单时,我想关闭第一个导航下拉菜单。 Check here https://kctherapy.com/our-team/ .在此处查看https://kctherapy.com/our-team/

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

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