title: javascript - click event target exclude child
body: <p>I trying make a menu with sub-menu. How to exclude click event on child item? In my snippet, when I click on child item. Parent was remove <code>.open</code> class.</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>var menu = document.querySelectorAll('#menu &gt; li')
  if (menu.length) {
    for (var i = 0; i &lt; menu.length; i++) {
      if (menu[i].classList.contains('has-sub')) {
        menu[i].addEventListener('click', function(event) {
            event.currentTarget.classList.toggle('open')
        })
      }
    }
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.sub-menu { display: none }
  .has-sub.open .sub-menu { display: block }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;ul id="menu"&gt;
    &lt;li class="has-sub"&gt;
      &lt;a href="#"&gt;Sub-memu&lt;/a&gt;
      &lt;ul class="sub-menu"&gt;
        &lt;li&gt;&lt;a href="#"&gt;Item&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/li&gt;
  &lt;/ul&gt;</code></pre>
  </div>
  </div>
  </p>