title: Add an "click outside of menu to close" jQuery / Javascript to a menu drop-up that has .toggle()
body: <p>I would like to add the function to close the menu if I click outside the menu. </p>
  
  <p>And also keep the menu button working to close it too: <a href="https://jsfiddle.net/ezkay/1he5bhzt/" rel="nofollow noreferrer">https://jsfiddle.net/ezkay/1he5bhzt/</a></p>
  
  <pre><code>$(document).ready(function () {
      $("li").click(function () {
          $('li &gt; ul').not($(this).children("ul").toggle()).hide();
      });
  });
  </code></pre>
  
  <p>Also can you tell me if this is correct for mobile etc? I hope and think so, because it's using .click, right?</p>
  
  <p>This is referring to this post, that I can't reply to the answer to ask there:
  <a href="https://stackoverflow.com/questions/23043151/how-to-change-drop-down-menu-to-drop-up-menu">How to change drop-down menu to drop-up menu</a></p>