Skip to content
Advertisement

Vanilla JS Multi level navigation is not working in sublevels

I created a very basic HTML multi navigation and it is working from first level. But it is not working on second level menu. For example. In my menu “About” page has submenu and inside of About menu “Profile” menu has another submenus. But when i click on “Profile” menu, it is not working. Can anyone help me to fix this. Thanks in Advance!

JavaScript
JavaScript
JavaScript

Advertisement

Answer

The thing is everything works on your code. But when clicking on a .has-submenu that is itself inside a .has-submenu the event listener is triggered for each element. I’ve added a topPropagation for the event to not bubble up, this will effectively prevent triggering on the parent .has-submenu.

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement