title: Toggle the display of a ul submenu only if parent li is clicked
body: <p>I've looked through some of the other questions on this site that I thought might help, like <a href="https://stackoverflow.com/questions/25638055/how-to-make-a-submenu-display-only-if-the-li-is-clicked">this one</a> and <a href="https://stackoverflow.com/questions/3660855/hide-all-visible-ul-when-parent-li-is-clicked">this one</a>, but they don't seem to answer my question. What I have is the following:</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>$(document).ready(function() {
   $(".has-submenu ul").hide();
    $(".has-submenu").click(function() {
     $(this).children("ul").toggle();
    });
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;ul&gt;
    &lt;li&gt;&lt;a href="#"&gt;Item 1&lt;/a&gt;&lt;/li&gt;
    &lt;li class="has-submenu"&gt;&lt;a href="#"&gt;Item 2&lt;/a&gt;
      &lt;ul&gt;
        &lt;li&gt;&lt;a href="#"&gt;Sub Item 1&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/li&gt;
  &lt;/ul&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>As you can see from this snippet, the submenu is hidden regardless of whether I click "Item 2" or "Sub Item 1". I realize this is because "Sub Item 1" is part of the <code>&lt;li class="has-submenu"&gt;</code>, so of course once it's clicked it goes through and toggles the sub menu. The CSS is doing what it's supposed to be doing, I just don't know how to tweak the CSS to say "Only hide the submenu if the parent <code>li</code> was clicked. I tried modifying the JQuery <code>click</code> function to look for <code>$(".has-submenu a")</code> to specify that it should only do that if that specific element was clicked, but that didn't seem to help.</p>
  
  <p>I'm sure it's an easy fix, I just don't know how to do it. Thanks!</p>