title: Check or uncheck the parent parents check box using jquery
body: <p>When I checked <strong>Account Settings</strong> checkbox all children li input tags are checked perfectly. but when I unchecked Children li checkbox <strong>Add</strong> and <strong>Delete</strong> it's unchecking <strong>Account Settings</strong> too.  </p>
  
  <p>I don't want to uncheck <strong>Account Settings</strong> when <strong>AS One</strong> and <strong>AS Two</strong> is checked. </p>
  
  <p>Help me out, how to solve this.</p>
  
  <p>Here <a href="https://jsfiddle.net/siddhuphp/e32zcp5k/" rel="nofollow noreferrer">Jsfiidle</a></p>
  
  <p>below is my code.</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;ul class="tree" id="tree"&gt;
      &lt;li&gt;
          &lt;input type="checkbox" name="account_settings" value="yes"&gt;Account Settings
          &lt;!-- AND SHOULD CHECK HERE --&gt;
          &lt;ul&gt;
              &lt;li&gt;
                  &lt;input type="checkbox" name="one" value="one"&gt;AS One&lt;/li&gt;
              &lt;li&gt;
                  &lt;input type="checkbox" name="two" value="two"&gt;AS Two&lt;/li&gt;
              &lt;li&gt;
                  &lt;input type="checkbox" name="user_roles" value="user_roles"&gt;Users &amp;amp; Roles
                  &lt;!-- SHOULD CHECK HERE --&gt;
                  &lt;ul&gt;
                      &lt;li&gt;
                          &lt;input type="checkbox" name="user_role" value="add"&gt;Add&lt;/li&gt;
                      &lt;li&gt;
                          &lt;input type="checkbox" name="user_role" value="delete"&gt;Delete&lt;/li&gt;
                      &lt;!-- CHECK HERE --&gt;
                  &lt;/ul&gt;
              &lt;/li&gt;
          &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;
          &lt;input type="checkbox" name="rl_module" value="yes"&gt;RL Module&lt;/li&gt;
      &lt;li&gt;
          &lt;input type="checkbox" name="rl_module" value="yes"&gt;Accounting
          &lt;ul&gt;
              &lt;li&gt;
                  &lt;input type="checkbox" name="vat" value="yes"&gt;VAT&lt;/li&gt;
              &lt;li&gt;
                  &lt;input type="checkbox" name="bank_account" value="yes"&gt;Banking
                  &lt;ul&gt;
                      &lt;li&gt;
                          &lt;input type="checkbox" name="view" value="yes"&gt;View&lt;/li&gt;
                      &lt;li&gt;
                          &lt;input type="checkbox" name="crud" value="yes"&gt;CRUD&lt;/li&gt;
                  &lt;/ul&gt;
              &lt;/li&gt;
          &lt;/ul&gt;
      &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p><strong>JS</strong></p>
  
  <pre><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"&gt;&lt;/script&gt;
  
  
  $('input[type=checkbox]').click(function () {
      $(this).parent().find('li input[type=checkbox]').prop('checked', $(this).is(':checked'));
      var sibs = false;
      $(this).closest('ul').children('li').each(function () {
             if($('input[type=checkbox]', this).is(':checked')) sibs=true;
      })
      $(this).parents('ul').prev().prop('checked', sibs);
  });
  </code></pre>