Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
February 20, 2022 08:27 am GMT

Multiple menu drop-downs with vanilla js

I looked all over online to find a solution to multiple drop down menus in a navigation header but most of the solutions I found in tutorials involved duplicating a Javascript function that targets the individual ID of the parent container for the drop down.

A couple issues I found with this:

  • If each drop down has it's own function, then more than one drop down can be open at the same time.

  • Clicking anywhere else on the page to close the drop down was tricky and confusing.

Now, I know this is super simple to implement with something like Alpine.js (which in all reality I'd probably use in the real world instead) but I wanted to make this work with Vanilla JS, so this was the solution I came up with.

If anyone has feedback I'd really appreciate it!


Original Link: https://dev.to/wyattmarshalldev/multiple-menu-drop-downs-with-vanilla-js-29d5

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To