title: Collapsing and expanding multiple nested rows in jQuery
body: <p>I need a little help with collapsing and expanding nested rows. Currently my code below expands and collapses as desired at the first level but the subsequent levels also show.</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(e) {
    $('.collapseTitle').click(function() {
      $(this).parent()
        .parent()
        .next('tbody')
        .toggleClass('collapsed');
    });
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.collapsed {
    display: none;
  }</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;table&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;td class="collapseTitle"&gt;Title&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
  
    &lt;tbody class="collapsed"&gt;
      &lt;tr&gt;
        &lt;td&gt;Level 1&lt;/td&gt;
      &lt;/tr&gt;
  
      &lt;tr&gt;
        &lt;td&gt;Level 2&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I am trying to achieve that Level 1 expands when "collapseTitle" is clicked and that only when "collapseAccount" is clicked, does Level 2 expand. Now I know that my code should look something like the below, but I am struggling...</p>
  
  <pre><code>&lt;table&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;td class="collapseTitle"&gt;Title&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
  
    &lt;tbody&gt;
      &lt;tr class="collapsed account"&gt;
        &lt;td class="collapseAccount"&gt;Level 1&lt;/td&gt;
      &lt;/tr&gt;
  
      &lt;tr class="collapsed level"&gt;
        &lt;td&gt;Level 2&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  
  &lt;script&gt;
  $(document).ready(function(e) {
      $('.collapseTitle').click(function() {
          $(this).parent().parent().next('tbody tr').toggleClass('account');
      });
  });
  
  $(document).ready(function(e) {
      $('.collapseAccount').click(function() {
          $(this).next('tr').toggleClass('level');
      });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>