title: How to use Javascript to close css drop down menu on outside click?
body: <p>I want to use pure javascript (not jquery) to close a pure css drop-down menu I have created when clicking outside of the menu. How can I do this?</p>
  
  <p><strong>HTML:</strong></p>
  
  <pre><code>&lt;ul&gt;
      &lt;div class="submenu"&gt;
          &lt;ul&gt;&lt;/ul&gt;
      &lt;/div&gt;
      &lt;div class="submenu"&gt;
          &lt;ul&gt;&lt;/ul&gt;
      &lt;/div&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>That's the basic structure of my HTML. I want to close the submenu if clicking outside of the submenu. Any way to do so with pure javascript? So far I've tried this:</p>
  
  <p><strong>Javascript:</strong></p>
  
  <pre><code>        &lt;script&gt;
              document.onclick = closeMenu();
              function closeMenu() {
                  document.getElementsByClassName("submenu").style.display = 'none';
              }
          &lt;/script&gt;
  </code></pre>
  
  <p>This doesn't seem to work. Any ideas?</p>