title: addEventListener with getElementsByClassName
body: <p>I am trying to create a dropdown menu in javascript (vanilla). I know how to do it in CSS, but i will never really understand Javascript if i don't try to do things in Javascript, hence the question.</p>
  
  <p>My issue is that i cannot work out how to use the array from <code>getElementsByClassName</code> and loop it to target only the <code>&lt;li&gt;</code> that was clicked. I have googled until my head hurts, This is due to a lack of understanding/knowledge on how to get/use arrays with an <code>onclick</code> event with a loop. If someone could kindly help me out with this</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function startUp() {
      subMenu();
  }
  
  function subMenu() {
      var menu = document.getElementById('Menu').addEventListener('click', subMenu);
      var drop = document.getElementsByClassName('sub');
          for (i = 0; i &lt; drop.length; i++){
              drop += drop.length;
              if (drop.style.display === 'none') {
                  drop.style.display = 'inline-block';
              }else {
                  drop.style.display = 'none';
              }
          }
  }
  window.onload = startUp;</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;nav id="Menu"&gt;
      &lt;ul&gt;
          &lt;li&gt;Home&lt;/li&gt;
          &lt;li&gt;Members&lt;/li&gt;
          &lt;li&gt;Gallery
              &lt;ul class="sub" style="display: none;"&gt;
                  &lt;li&gt;link&lt;/li&gt;
                  &lt;li&gt;link 1&lt;/li&gt;
                  &lt;li&gt;link 2&lt;/li&gt;
                  &lt;li&gt;link 3&lt;/li&gt;
              &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;Contact
              &lt;ul class="sub" style="display: none;"&gt;
                  &lt;li&gt;E-Mail&lt;/li&gt;     
              &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;Steam Community&lt;/li&gt;
          &lt;li&gt;Youtube&lt;/li&gt;
      &lt;/ul&gt;
  &lt;/nav&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I have tried multiple different variations of code all afternoon, I just cannot seem to get it all to work together, without writing multiple functions for ID's instead of using classes.</p>