Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code> &lt;div id="page-wrap"&gt; &lt;h1&gt;Indeterminate Checkboxes&lt;/h1&gt; &lt;ul&gt; &lt;li&gt; &lt;input type="checkbox" name="tall" id="tall"&gt; &lt;label for="tall"&gt;Tall Things&lt;/label&gt; &lt;ul&gt; &lt;li&gt; &lt;input type="checkbox" name="tall-1" id="tall-1"&gt; &lt;label for="tall-1"&gt;Buildings&lt;/label&gt; &lt;/li&gt; &lt;li&gt; &lt;input type="checkbox" name="tall-2" id="tall-2"&gt; &lt;label for="tall-2"&gt;Giants&lt;/label&gt; &lt;ul&gt; &lt;li&gt; &lt;input type="checkbox" name="tall-2-1" id="tall-2-1"&gt; &lt;label for="tall-2-1"&gt;Andre&lt;/label&gt; &lt;/li&gt; &lt;li&gt; &lt;input type="checkbox" name="tall-2-2" id="tall-2-2"&gt; &lt;label for="tall-2-2"&gt;Paul Bunyan&lt;/label&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt; &lt;input type="checkbox" name="tall-3" id="tall-3"&gt; &lt;label for="tall-3"&gt;Two sandwiches&lt;/label&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt; &lt;input type="checkbox" name="short" id="short"&gt; &lt;label for="short"&gt;Short Things&lt;/label&gt; &lt;ul&gt; &lt;li&gt; &lt;input type="checkbox" name="short-1" id="short-1"&gt; &lt;label for="short-1"&gt;Smurfs&lt;/label&gt; &lt;/li&gt; &lt;li&gt; &lt;input type="checkbox" name="short-2" id="short-2"&gt; &lt;label for="short-2"&gt;Mushrooms&lt;/label&gt; &lt;/li&gt; &lt;li&gt; &lt;input type="checkbox" name="short-3" id="short-3"&gt; &lt;label for="short-3"&gt;One Sandwich&lt;/label&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; $(function() { // Apparently click is better chan change? Cuz IE? $('input[type="checkbox"]').change(function(e) { var checked = $(this).prop("checked"), container = $(this).parent(), siblings = container.siblings(); container.find('input[type="checkbox"]').prop({ indeterminate: false, checked: checked }); function checkSiblings(el) { var parent = el.parent().parent(), all = true; el.siblings().each(function() { return all = ($(this).children('input[type="checkbox"]').prop("checked") === checked); }); if (all &amp;&amp; checked) { parent.children('input[type="checkbox"]').prop({ indeterminate: false, checked: checked }); checkSiblings(parent); } else if (all &amp;&amp; !checked) { parent.children('input[type="checkbox"]').prop("checked", checked); parent.children('input[type="checkbox"]').prop("indeterminate", (parent.find('input[type="checkbox"]:checked').length &gt; 0)); checkSiblings(parent); } else { el.parents("li").children('input[type="checkbox"]').prop({ indeterminate: true, checked: false }); } } checkSiblings(container); }); }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload