title: How to add active state for "nested" accordion
body: <p>I found this efficient and practical nested accordion using 'ul' at codepen here: <a href="https://codepen.io/brenden/pen/Kwbpyj" rel="nofollow">https://codepen.io/brenden/pen/Kwbpyj</a></p>
  
  <p>It's as 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>$('.toggle').click(function(e) {
     e.preventDefault();
    
      var $this = $(this);
    
      if ($this.next().hasClass('show')) {
          $this.next().removeClass('show');
          $this.next().slideUp(350);
      } else {
          $this.parent().parent().find('li .inner').removeClass('show');
          $this.parent().parent().find('li .inner').slideUp(350);
          $this.next().toggleClass('show');
          $this.next().slideToggle(350);
      }
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>url('http://fonts.googleapis.com/css?family=Pacifico|Open+Sans:300,400,600');
  * {
    box-sizing: border-box;
    font-family: 'Open Sans', sans-serif;
    font-weight: 300;
  }
  .active {
    text-decoration: underline !important;
  }
  a {
    text-decoration: none;
    color: inherit;
  }
  p {
    font-size: 1.1em;
    margin: 1em 0;
  }
  .description {
    margin: 1em auto 2.25em;
  }
  body {
    width: 40%;
    min-width: 300px;
    max-width: 400px;
    margin: 1.5em auto;
    color: #333;
  }
  h1 {
    font-family: 'Pacifico', cursive;
    font-weight: 400;
    font-size: 2.5em;
  }
  ul {
    list-style: none;
    padding: 0;
  }
  ul .inner {
    padding-left: 1em;
    overflow: hidden;
    display: none;
  }
  ul .inner.show {
    /*display: block;*/
  }
  ul li {
    margin: .5em 0;
  }
  ul li a.toggle {
    width: 100%;
    display: block;
    background: rgba(0, 0, 0, 0.78);
    color: #fefefe;
    padding: .75em;
    border-radius: 0.15em;
    transition: background .3s ease;
  }
  ul li a.toggle:hover {
    background: rgba(0, 0, 0, 0.9);
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"&gt;&lt;/script&gt;
  &lt;h1&gt;A Cool Accordion&lt;/h1&gt;
  
  &lt;p class="description"&gt;
    You could simply toggle the .show class (if display: block is uncommented in the CSS) in JavaScript, but you'll lose the animation.
  &lt;/p&gt;
  
  &lt;ul class="accordion"&gt;
    &lt;li&gt;
      &lt;a class="toggle" href="javascript:void(0);"&gt;Item 1&lt;/a&gt;
      &lt;ul class="inner"&gt;
        &lt;li&gt;Option 1&lt;/li&gt;
        &lt;li&gt;Option 2&lt;/li&gt;
        &lt;li&gt;Option 3&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a class="toggle" href="javascript:void(0);"&gt;Item 2&lt;/a&gt;
      &lt;ul class="inner"&gt;
        &lt;li&gt;Option 1&lt;/li&gt;
        &lt;li&gt;Option 2&lt;/li&gt;
        &lt;li&gt;Option 3&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a class="toggle" href="javascript:void(0);"&gt;Item 3&lt;/a&gt;
      &lt;ul class="inner"&gt;
        &lt;li&gt;
          &lt;a href="#" class="toggle"&gt;Open Inner&lt;/a&gt;
          &lt;div class="inner"&gt;
            &lt;p&gt;
              Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas tempus placerat fringilla. Duis a elit et dolor laoreet volutpat. Aliquam ultrices mauris id mattis imperdiet. Aenean cursus ultrices justo et varius. Suspendisse aliquam orci id dui dapibus
              blandit. In hac habitasse platea dictumst. Sed risus velit, pellentesque eu enim ac, ultricies pretium felis.
            &lt;/p&gt;
          &lt;/div&gt;
        &lt;/li&gt;
        
        &lt;li&gt;
          &lt;a href="#" class="toggle"&gt;Open Inner #2&lt;/a&gt;
          &lt;div class="inner"&gt;
            &lt;p&gt;
              Children will automatically close upon closing its parent.
            &lt;/p&gt;
          &lt;/div&gt;
        &lt;/li&gt;
        
        &lt;li&gt;Option 3&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a class="toggle" href="javascript:void(0);"&gt;Item 4&lt;/a&gt;
      &lt;ul class="inner"&gt;
        &lt;li&gt;
          &lt;a href="#" class="toggle"&gt;Technically any number of nested elements&lt;/a&gt;
          &lt;ul class="inner"&gt;
            &lt;li&gt;
              &lt;a href="#" class="toggle"&gt;Another nested element&lt;/a&gt;
              &lt;div class="inner"&gt;
                &lt;p&gt;
                  As long as the inner element has inner as one of its classes then it will be toggled.
                &lt;/p&gt;
                &lt;p&gt;
                  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas tempus placerat fringilla. Duis a elit et dolor laoreet volutpat. Aliquam ultrices mauris id mattis imperdiet. Aenean cursus ultrices justo et varius. Suspendisse aliquam orci id dui dapibus
                  blandit. In hac habitasse platea dictumst. Sed risus velit, pellentesque eu enim ac, ultricies pretium felis.
                &lt;/p&gt;
              &lt;/div&gt;
            &lt;/li&gt;
          &lt;/ul&gt;
        &lt;/li&gt;
        
        &lt;li&gt;Option 2&lt;/li&gt;
        
        &lt;li&gt;Option 3&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/li&gt;
  &lt;/ul&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>But it doesn't support active state by adding for example '.active' class for the opened title.</p>
  
  <p>Also Look at the "Item 3". When you click on nested 'a', the '.active' class of 'a' inside the active 'li' parents are removed. The point here is how can i keep them active while i click on nested 'a'?</p>
  
  <p>So can you help me to do that?</p>