title: jquery subgrouped checkboxes
body: <p>I have a country list. It's splitted up 3 times.</p>
  
  <pre><code>[ ] World
      [ ] Africa
          [ ] Congo
      [ ] Europe
          [ ] Netherlands, the
          [ ] Italy
  </code></pre>
  
  <p>now if I click world, I want all of them to be checked.
  If I click Africa, I only want Congo to be checked.
  If I click Europe, Both Italy and Netherlands, the should be checked.
  If I click Netherlands, the, and Italy, Europe should be checked, and the same should happen with World when clicking Europe and Africa.
  I came up with the following jquery script for it:</p>
  
  <pre><code>$(function() {
      $(":checkbox").click(function() {
          var maxlevel = 3;
          var level = $(this).attr("class").substring(5, 6);
          var level_checked = $(this).attr("checked");
          //update children
          $('input', $(this).parent('div')).each(function() {
              var curlevel = $(this).attr("class").substring(5, 6);
              if (curlevel &gt; level) {
                  $(this).attr("checked", level_checked);
              }
          });
          //update parents?
      });
  });
  </code></pre>
  
  <p>I am using the following html code:</p>
  
  <pre><code>&lt;div&gt;
      &lt;input class="layer1" type="checkbox" /&gt;Layer1 &lt;br /&gt;
      &lt;div&gt;
          &lt;input class="layer2" type="checkbox" /&gt;Layer2 &lt;br /&gt;
          &lt;div&gt;
              &lt;input class="layer3" type="checkbox" /&gt;Layer3 &lt;br /&gt;
              &lt;input class="layer3" type="checkbox" /&gt;Layer3 &lt;br /&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div&gt;
          &lt;input class="layer2" type="checkbox" /&gt;Layer2 &lt;br /&gt;
          &lt;div&gt;
              &lt;input class="layer3" type="checkbox" /&gt;Layer3 &lt;br /&gt;
              &lt;input class="layer3" type="checkbox" /&gt;Layer3 &lt;br /&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Updating the children when clicking something works, but updating the parents when clicking a box.. I have no idea how to get that done. I found 2 pieces of code that did this, but they only worked for 1 'subgroup' of checkboxes, and not for 2 like in my case.</p>
  
  <p>Can anyone help me out here?</p>