title: jQuery selecting all child checkboxes
body: <p>Firstly, just wanted to say I am hopeless with jQuery.</p>
  
  <p>I was looking at some code from a post on here which selects each parent checkbox (and works):</p>
  
  <pre><code>$(function() {
    $(":checkbox").change(function () {
      $(this).parents().children(':checkbox').attr('checked', this.checked);
    });
  });
  </code></pre>
  
  <p>We have a tree view structure using <code>&lt;ul&gt; &lt;li&gt;</code> and each <code>&lt;li&gt;</code> has a checkbox.
  I want to do the opposite of the above and perform the same checkbox selection on all child checkboxes.</p>
  
  <p>Can anyone modify the above to do that?</p>
  
  <p>Just to note we are using razor and each checkbox is a @Html.CheckboxFor so the output is along the lines of: </p>
  
  <pre><code>&lt;input name="Survey.Buildings[0].IsSelected" type="checkbox" value="true" checked="checked" data-val="true" data-val-required="The Selected? field is required." id="Survey_Buildings_0__IsSelected" /&gt;
  &lt;input name="Survey.Buildings[0].IsSelected" type="hidden" value="false" /&gt;
  </code></pre>
  
  <ul>
  <li>EDIT 2:</li>
  </ul>
  
  <p>OK I have fixed the HTML and the structure now looks like:</p>
  
  <pre><code>&lt;ul&gt;
      &lt;li&gt; Cbx1
          &lt;ul&gt;
              &lt;li&gt; Cbx 2 &lt;/li&gt;
          &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt; Cbx3 &lt;/li&gt;
      &lt;li&gt; Cbx4   
          &lt;ul&gt;
              &lt;li&gt; Cbx 5 &lt;/li&gt;
              &lt;li&gt; Cbx 6 &lt;/li&gt;
          &lt;/ul&gt;
      &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>So if Cbx4 was checked Cbx5 and 6 would be checked, and if it was unchecked they would be unchecked</p>
  
  <p>Much appreciated</p>
  
  <p>Andy</p>