Clickable Dropdown Menu

In this step-by-step tutorial, you'll learn how to create a clickable dropdown menu instead of the default hover…

Tools

Code editor

Estimated time

5 min.

Adding Class Suffix

1. The class suffix clickable-dropdown should be placed in the "Class Suffix" field of the Menu plugin.

Adding CSS

2. Copy CSS code below, go to Tools ➝ Code Editor ➝ CSS and paste it.

 

@media (min-width: 1025px) { .clickable-dropdown .mod-menu li.deeper > .mod-menu__sub:not(.dropdown-visible) { display: none !important; } .clickable-dropdown .mod-menu .dropdown-visible { box-sizing: border-box !important; display: block !important; } .clickable-dropdown .mod-menu__sub > li.deeper > .mod-menu__sub.dropdown-visible { left: 100%; position: absolute; top: 0 !important; }} 

Adding JavaScript

3. Copy JavaScript code below, go to Tools ➝ Code Editor ➝ JavaScript and paste it.

 

$(document).ready(function () { if (window.matchMedia("(min-width: 1025px)").matches) { $('.clickable-dropdown .mod-menu li.deeper.parent > a').on('click', function (e) { e.preventDefault(); e.stopPropagation(); const currentParent = $(this).parent('li'); const currentSubmenu = currentParent.children('.mod-menu__sub').first(); currentParent .siblings('li.deeper.parent') .children('.mod-menu__sub.dropdown-visible') .removeClass('dropdown-visible'); if (!currentSubmenu.hasClass('dropdown-visible')) { currentSubmenu.addClass('dropdown-visible'); } else { currentSubmenu.removeClass('dropdown-visible'); } }); $(document).on('click', function (e) { if ($(e.target).closest('.clickable-dropdown .mod-menu').length === 0) { $('.clickable-dropdown .mod-menu__sub').removeClass('dropdown-visible'); } }); }}); 

Something is not clear? Ask a question on community forums.