title: Highlight parent menu when submenu is clicked in Jquery (accordion menu)
body: <pre><code> &lt;ul class="acd" &gt;
      &lt;li class="item1"&gt; 
           &lt;a href="#"&gt;Parent 1&lt;/a&gt;
          &lt;ul class="smenu"&gt;
              &lt;li&gt;&lt;a href="subpage1"&gt;Child 1&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href="subpage2"&gt;Child 2&lt;/a&gt;&lt;/li&gt;      
          &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li class="item2"&gt; 
          &lt;a href="#"&gt;Parent 2&lt;/a&gt;
          &lt;ul class="smenu"&gt;
              &lt;li&gt;&lt;a href="subpage3"&gt;Child 1&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href="subpage4"&gt;Child 2&lt;/a&gt;&lt;/li&gt;      
          &lt;/ul&gt;
      &lt;/li&gt;
   &lt;/ul&gt;
  
  Jquery:
  &lt;script type="text/javascript"&gt;
  
      $(document).ready( function() {
  
              // initialize accordion
              $('.acd ul').each( function() {
  
                  var currentURI = window.location.href;
                  var links = $('a', this);
                  var collapse = true;
                  for (var i = 0; i &lt; links.size(); i++) {
                      var elem = links.eq(i);
                      var href = elem.attr('href');
                      var hrefLength = href.length;
                      var compareTo = currentURI.substr(-1*hrefLength);
  
                      if (href == compareTo) {
  
                          collapse = false;
                          break;
                      }
                  };
                  if (collapse) {
                      $(this).hide();
                  }
              });
  
  
              // on click, show this element and hide all others
  
              $('.acd &gt; li').click( function() {
  
                  var me = $(this).children('ul');                    
                  $('.acd ul').not(me).slideUp('normal');
                  me.slideDown('normal');
  
              });
  
  
  
  
  });
  
  &lt;/script&gt;
  </code></pre>
  
  <p>CSS:</p>
  
  <pre><code>.acd,
  .acd ul,
  .acd li,
  .acd a,
  .acd span {
      margin: 0;
      padding: 0;
      border: none;
      outline: none;
  border-radius: 2px; 
  -moz-border-radius: 2px; 
  -webkit-border-radius: 2px; 
  
  }
  
  
  
  .acd li {
      list-style: none;
  }
  
  
  .acd li &gt; a {
      display: block;
      position: relative;
      min-width: 110px;
      padding: 0 10px 0 40px;
  
      color: #fdfdfd;
      font: bold 12px/32px Arial, sans-serif;
      text-decoration: none;
      text-shadow: 0px 1px 0px rgba(0,0,0, .35);
  
      background: #616975;
      background: -moz-linear-gradient(top,  rgb(114, 122, 134) 0%, rgb(80, 88, 100) 100%);
      background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgb(114, 122, 134)), color-stop(100%,rgb(80, 88, 100)));
      background: -webkit-linear-gradient(top,  rgb(114, 122, 134) 0%,rgb(80, 88, 100) 100%);
      background: -o-linear-gradient(top,  rgb(114, 122, 134) 0%,rgb(80, 88, 100) 100%);
      background: -ms-linear-gradient(top,  rgb(114, 122, 134) 0%,rgb(80, 88, 100) 100%);
      background: linear-gradient(top,  rgb(114, 122, 134) 0%,rgb(80, 88, 100) 100%);
  
      -webkit-box-shadow: inset 0px 1px 0px 0px rgba(255,255,255, .1), 0px 1px 0px 0px rgba(0,0,0, .1);
      -moz-box-shadow: inset 0px 1px 0px 0px rgba(255,255,255, .1), 0px 1px 0px 0px rgba(0,0,0, .1);
      box-shadow: inset 0px 1px 0px 0px rgba(255,255,255, .1), 0px 1px 0px 0px rgba(0,0,0, .1);
  }
  
  .acd li &gt; a span {
      display: block;
      position: absolute;
      top: 7px;
      right: 0;
      padding: 0 10px;
      margin-right: 10px;
  
      font: normal bold 12px/18px Arial, sans-serif;
      background: #404247;
  
      -webkit-border-radius: 15px;
      -moz-border-radius: 15px;
      border-radius: 15px;
  
      -webkit-box-shadow: inset 1px 1px 1px rgba(0,0,0, .2), 1px 1px 1px rgba(255,255,255, .1);
      -moz-box-shadow: inset 1px 1px 1px rgba(0,0,0, .2), 1px 1px 1px rgba(255,255,255, .1);
      box-shadow: inset 1px 1px 1px rgba(0,0,0, .2), 1px 1px 1px rgba(255,255,255, .1);
  }
  
  .smenu li a {
      color: #878d95;
      text-shadow: 1px 1px 0px rgba(255,255,255, .2);
  
      background: #f2f2f2;
      border-bottom: 1px solid #d6d6d6;
  
      -webkit-box-shadow: inset 0px 1px 0px 0px rgba(255,255,255, .1), 0px 1px 0px 0px rgba(0,0,0, .1);
      -moz-box-shadow: inset 0px 1px 0px 0px rgba(255,255,255, .1), 0px 1px 0px 0px rgba(0,0,0, .1);
      box-shadow: inset 0px 1px 0px 0px rgba(255,255,255, .1), 0px 1px 0px 0px rgba(0,0,0, .1);
  }
  
  .smenu li:last-child a { border: none; }
  
  .smenu li &gt; a span {
      color: #797979;
      text-shadow: 1px 1px 0px rgba(255,255,255, .2);
      background: transparent;
      border: 1px solid #c9c9c9;
  
      -webkit-box-shadow: none;
      -moz-box-shadow: none;
      box-shadow: none;
  }
  
  .smenu em {
      position: absolute;
      top: 0;
      left: 0;
      margin-left: 14px;
      color: #a6a6a6;
      font: normal 10px/32px Arial, sans-serif;
  }
  
  
  
  .acd &gt; li:target &gt; a,
  .acd &gt; li &gt; a.active {
      color: #00121c;
      text-shadow: 1px 1px 1px rgba(255,255,255, .2);
  
      /*background: url(../img/active.png) repeat-x;*/
      background: #0088cd;
      background: -moz-linear-gradient(top,  #0088cd 0%, #00669a 100%);
      background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#0088cd), color-stop(100%,#00669a));
      background: -webkit-linear-gradient(top,  #0088cd 0%,#00669a 100%);
      background: -o-linear-gradient(top,  #0088cd 0%,#00669a 100%);
      background: -ms-linear-gradient(top,  #0088cd 0%,#00669a 100%);
      background: linear-gradient(top,  #0088cd 0%,#00669a 100%);
  }
  
  
  .smenu li:hover a { background: #f7f7f7; }
  
  
  
  .acd li &gt; .smenu {
      display: block;
  }
  
  .acd li:target &gt; .smenu {
      display: block;
  }
  </code></pre>
  
  <p>I wanted the accordion menu to drop down and highlight the parent when the child menu is clicked, the dropdown menu is supposed to remain open for the clicked link with parent li highlighted. If I click on the parent link where the parent has no child, the highlight will be at the parent.</p>