- How to close one javascript drop down menu when opening another?
- How to close a dropdown automatically in Javascript?
How to close one javascript drop down menu when opening another?
addEventListener("click", event => // start by closing every dropdown for (let dd of dropdown) dd. classList. toggle("open", false); // then if a link was clicked, open the associated dropdown if (event. target.
How to close a dropdown automatically in Javascript?
To do this, you can add custom JS functions that will open dropdowns based on element ID, and when one dropdown is opened, all others will be closed. You can create a function that closes all the dropdowns. Then, in your "open" function, call the "close_all" function first.