title: jQuery check the parent checkbox if the child checkbox is checked
body: <p>I want to make a logic that if a child checkbox is checked, it checks the parent checkbox too. The input can parent, child and both:</p>
  
  <pre><code>&lt;input type="checkbox" name="checkbox[$counter]" class="parent" /&gt;
  &lt;input type="checkbox" name="checkbox[$counter]" class="child" /&gt;
  &lt;input type="checkbox" name="checkbox[$counter]" class="parent child" /&gt;
  </code></pre>
  
  <p>This structure:</p>
  
  <ul>
  <li>1
  
  <ul>
  <li>2</li>
  <li>3</li>
  </ul></li>
  <li>4
  
  <ul>
  <li>5
  
  <ul>
  <li>6</li>
  <li>7</li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p>will be look like this:</p>
  
  <pre><code>&lt;table class="table"&gt;
    &lt;tr&gt;
      &lt;td&gt;
        &lt;input type="checkbox" name="checkbox[1]" class="parent" /&gt;
      &lt;/td&gt;
      &lt;td&gt;
       .
       .
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;
        &lt;input type="checkbox" name="checkbox[2]" class="child" /&gt;
      &lt;/td&gt;
      &lt;td&gt;
       .
       .
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;
        &lt;input type="checkbox" name="checkbox[3]" class="child" /&gt;
      &lt;/td&gt;
      &lt;td&gt;
       .
       .
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;
        &lt;input type="checkbox" name="checkbox[4]" class="parent" /&gt;
      &lt;/td&gt;
      &lt;td&gt;
       .
       .
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;
        &lt;input type="checkbox" name="checkbox[5]" class="child parent" /&gt;
      &lt;/td&gt;
      &lt;td&gt;
       .
       .
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;
        &lt;input type="checkbox" name="checkbox[6]" class="child" /&gt;
      &lt;/td&gt;
      &lt;td&gt;
       .
       .
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;
        &lt;input type="checkbox" name="checkbox[7]" class="child" /&gt;
      &lt;/td&gt;
      &lt;td&gt;
       .
       .
    &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>I want if I check 3, it checks 1 and if I check 6 it checks 5 and 4, too.</p>
  
  <p>Also the checkboxes are in separate table rows, becouse I want to show some information structured in table next to the checkbox.</p>
  
  <p>Can you show me a script what does it? I tried this, but it's not working:</p>
  
  <pre><code>$(document).ready(function() {
      $('input.child').change(function() {
          if ($(this).is(':checked')) {
              $(this).closest('input.parent:checkbox').attr('checked', true);
          }
      });
  });
  </code></pre>