0

I made a wordpress page with divi and want to close the nav-menu when the user clicks outside. How can I achieve this?

Here is the code (I think this part is relevant)

<div id="et_mobile_nav_menu">
<div class="mobile_nav closed">
<span class="select_page">Seite auswählen</span>
<span class="mobile_menu_bar mobile_menu_bar_toggle"></span>

and my actual script looks like that

<script type="text/javascript">
  (function($) {
      $(document).ready(function() {
        console.log('onReady');
        $(document).on('click','.mobile_menu_bar_toggle',function(){
          console.log('working?');
      });
   });
})(jQuery);
</script>

Because the drawer-toggle gets added dynamically, I better choose the "on"-method to interact with it, right?

As always, thanks in advance.

Martin Pfeffer
  • 12,471
  • 9
  • 59
  • 68
  • 1
    Have you considered hiding the menu on blur? – rybo111 Mar 04 '17 at 18:14
  • 2
    look at this -> [check those answers](http://stackoverflow.com/questions/2868582/click-outside-menu-to-close-in-jquery) – Danail Videv Mar 04 '17 at 18:18
  • 1
    Did you try this code? `$('.mobile_menu_bar_toggle').click(function(){ alert('Clicked'); });` – wpcoder Mar 04 '17 at 23:38
  • Thanks buddies! Works like a charm :) I wrote a little blog post https://celox.io/divi-theme-navigationsmenue-automatisch-einklappen/ (its in German, but contains the code) Kudos to you! – Martin Pfeffer Mar 05 '17 at 20:19

0 Answers0