- How to close one javascript drop-down menu when opening another?
- How do I create a nested drop-down menu in HTML?
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 do I create a nested drop-down menu in HTML?
Create A Subnav
Use any element to open the subnav/dropdown menu, e.g. a <button>, <a> or <p> element. Use a container element (like <div>) to create the subnav menu and add the subnav links inside it. Wrap a <div> element around the button and the <div> to position the subnav menu correctly with CSS.