...

/

Implementing the Behavior of Dropdown Menu

Implementing the Behavior of Dropdown Menu

This lesson is a step-by-step guide on how to implement a working dropdown menu in JavaScript.

Toggling submenu visibility #

First thing’s first: the submenu shouldn’t be visible when a menu item isn’t hovered over. Let’s set the display: none property to be the default state, and when a menu item is hovered, it toggles back to display: block.

We’ll find all the elements that are of the class name menu__main__item, and iterate through them so that we can bind functions to events. When one of these items get the event onmouseenter triggered, the function menuItemEnter is called. menuItemEnter finds the submenu by the class name, and sets the display property.

Do you see the issue ...