title: How to close previous opened sub menu when clicked on next submenu on click event
body: <p>I have one menu with sub menu.I have to open a drop down menu when clicked and closes again on when  clicked on other menu. My below code both the drop down displaying if I clicked on menu. I have to display only one drop down at a time. Would you help me in this? </p>
  
  <p><strong>Note</strong> In second <code>li</code> tag I am using <code>div</code> tag</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>$('.sub-menu').hide();
     $("li:has(ul)").click(function(){
       $("ul",this).slideDown();
    });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.menu ul.nav-menu{
    list-style: none;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;div class="menu"&gt;
  &lt;ul class="nav-menu"&gt;
   
  &lt;li class="main-list"&gt;&lt;a href="#"&gt;home&lt;/a&gt;
  
   &lt;ul class="sub-menu"&gt;
    &lt;li&gt;&lt;a href="#"&gt;home1&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="#"&gt;home2&lt;/a&gt;&lt;/li&gt;
   &lt;/ul&gt;
  &lt;/li&gt;
  
  &lt;li class="main-list"&gt;&lt;a href="#"&gt;service&lt;/a&gt;
    &lt;div class="square"&gt;
    &lt;div class="sub"&gt;
    &lt;ul class="sub-menu"&gt;
     &lt;li&gt;&lt;a href="#"&gt;home1&lt;/a&gt;&lt;/li&gt;
     &lt;li&gt;&lt;a href="#"&gt;home2&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
     &lt;/div&gt;
   &lt;/div&gt;
  &lt;/li&gt;
  
  &lt;/ul&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>