How to hide the sub menu after a menu item link is clicked
Close desktop menu after click
If you are using a one page theme or have anchor links within your sub menus, and want to close the desktop menu as soon as one of the links is clicked:
- Install the TC Custom JavaScript Plugin
- Go to Appearance > Custom JavaScript and enter the following:
1 2 3 4 5 6 7 |
/* Max Mega Menu * Close the main menu as soon as a menu item is clicked */ jQuery(".mega-menu").on('after_mega_menu_init', function() { jQuery("li.mega-menu-item:not(.mega-menu-item-has-children) > a.mega-menu-link").on('click', function(e) { jQuery('.mega-menu').data('maxmegamenu').hideAllPanels(); }); }); |
Close mobile menu after click
If you are using a one page theme and want to close the mobile menu as soon as one of the links is clicked:
- Install the TC Custom JavaScript Plugin
- Go to Appearance > Custom JavaScript and enter the following:
1 2 3 4 5 6 7 8 |
/* Max Mega Menu * Close the mobile menu as soon as a menu item is clicked */ jQuery("ul.max-mega-menu").on("after_mega_menu_init", function() { var menu = jQuery(this); jQuery("li.mega-menu-item:not(.mega-menu-item-has-children) > a.mega-menu-link").on('click', function(e) { menu.data('maxmegamenu').hideMobileMenu(); }); }); |