This tutorial will teach you how to close the mobile toggle Elementor menu on clicking outside of it.
You will see, it's pretty simple to get this Elementor close menu on outside click working!
Demo:
First, add an HTML element close to your Elementor toggle nav menu
Add an HTML in your header template, close to your nav menu.
Under advanced, set it to position:absolute so that it doesn't occupy any flow space.
Then, copy paste this "Elementor Close Menu on Click" code
Copy paste it in the HTML element.
<script> document.addEventListener('DOMContentLoaded', function() { document.body.addEventListener('click', function(event) { if ( !event.target.closest('.elementor-nav-menu--toggle') && document.querySelector ('.elementor-menu-toggle.elementor-active')) { document.querySelector('.elementor-menu-toggle.elementor-active').click(); } }); }); </script>
Finally, enjoy your new Elementor close menu on outside click!
And that's it! Everything should be working fine.
2 Responses
Hi,
Thanks for the code but can we apply it to menu links instead of clicking outside.
Yes, I have a tutorial for that here : https://element.how/elementor-close-toggle-menu-on-same-page-anchor-links/