title: Display/hide sub list items in jQuery
body: <p>I have this list Items to show. I want to open A onclick and if I click B it opens B and closes automatically A. Now close the sub-menu just manually onclick if it's already opened, and this is fine, but I need the automatically closure too.</p>
  
  <pre><code>&lt;style&gt;
      #content_templ1 .expanded ul {display: none;}
  &lt;/style&gt;
  
  &lt;div class="leftsidebar_templ1"&gt;
      &lt;ul id="nav"&gt;
          &lt;li class="expanded"&gt;&lt;a class="on"&gt;Form a Compalny&lt;/a&gt;
              &lt;ul class="submuneu"&gt;
                  &lt;li&gt;&lt;a&gt;United Kingdom (UK)&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a&gt;United States of America (USA)&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a&gt;Classic Offshore&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a&gt;Alternative offshore Companies&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
          &lt;/li&gt;
  
          &lt;li class="expanded"&gt;&lt;a class="on"&gt;Office and address services&lt;/a&gt;
              &lt;ul class="submuneu"&gt;
                  &lt;li&gt;&lt;a&gt;Lorem Ipsum is simply&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a&gt;Contrary to popular belief&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a&gt;The standard chunk&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a&gt;There are many variations&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
          &lt;/li&gt;
  
          &lt;li class="expanded"&gt;&lt;a class="on"&gt;Nominee Services&lt;/a&gt;
              &lt;ul class="submuneu"&gt;
                  &lt;li&gt;&lt;a&gt;Lorem Ipsum is simply&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a&gt;Contrary to popular belief&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a&gt;The standard chunk&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a&gt;There are many variations&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
          &lt;/li&gt;
  
          &lt;li class="expanded"&gt;&lt;a class="on"&gt;Corporate Banking&lt;/a&gt;
              &lt;ul class="submuneu"&gt;
                  &lt;li&gt;&lt;a&gt;Lorem Ipsum is simply&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a&gt;Contrary to popular belief&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a&gt;The standard chunk&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a&gt;There are many variations&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
          &lt;/li&gt;
  
          &lt;li class="expanded"&gt;&lt;a&gt;Accountancy and Audit&lt;/a&gt;
              &lt;ul class="submuneu"&gt;
                  &lt;li&gt;&lt;a&gt;United Kingdom (UK)&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a&gt;United States of America (USA)&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a&gt;Classic Offshore&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a&gt;Alternative offshore Companies&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
          &lt;/li&gt;
  
          &lt;li class="expanded"&gt;&lt;a&gt;Name protection services&lt;/a&gt;
              &lt;ul class="submuneu"&gt;
                  &lt;li&gt;&lt;a&gt;Lorem Ipsum is simply&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a&gt;Contrary to popular belief&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a&gt;The standard chunk&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a&gt;There are many variations&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li class="expanded"&gt;&lt;a&gt;Making changes to a company&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;   
  
  &lt;/div&gt; 
  </code></pre>
  
  <p>jQuery:</p>
  
  <pre><code>&lt;script&gt;
  $(document).ready(function(){
      $('ul li.expanded &gt; a').click(function(event){
          $(this).parent().find('ul').slideToggle('slow');
      });
          $('a.on').click(function(){
          $('a.on').removeClass("active");
          $(this).addClass("active");
      });
  
  });
  &lt;/script&gt;
  </code></pre>