Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have changed the structure of your HTML (you can change this and make sure you change the jquery selectors accordingly) .</p> <pre><code> &lt;ul class="secLevel"&gt; &lt;li&gt;&lt;input id="pr1" type="checkbox" class='mainfilter' /&gt;&lt;h3&gt;Product 1&lt;/h3&gt; &lt;ul class="secLevel" id="pr1Items" &gt; &lt;li&gt;&lt;input id="107A-10" type="checkbox" /&gt;&lt;label for="107A-10"&gt;107A-10&lt;/label&gt;&lt;/li&gt; &lt;li&gt;&lt;input id="107A-11" type="checkbox" /&gt;&lt;label for="107A-11"&gt;107A-11&lt;/label&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/ul&gt; &lt;ul class="secLevel"&gt; &lt;li&gt;&lt;input id="pr2" type="checkbox" class='mainfilter' /&gt;&lt;h3&gt;Product 1&lt;/h3&gt; &lt;ul class="secLevel" id="pr1Items" &gt; &lt;li&gt;&lt;input id="someId1" type="checkbox" /&gt;&lt;label for="someId1"&gt;107A-10&lt;/label&gt;&lt;/li&gt; &lt;li&gt;&lt;input id="someId2" type="checkbox" /&gt;&lt;label for="someId2"&gt;107A-11&lt;/label&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/ul&gt; </code></pre> <p>jquery</p> <pre><code>$('.mainfilter').change(function() { if($(this).is(':checked')){ $(this).parent().next('ul').children().attr('checked','checked'); }else{ $(this).parent().next('ul').children().removeAttr('checked'); } }); </code></pre> <p>For top level check box</p> <pre><code>&lt;input id="parentChkId" type="checkbox" /&gt; $('#parentChkId').change(function() { if($(this).is(':checked')){ $('#parentChkId input:checkbox').attr('checked','checked'); }else{ $('#parentChkId input:checkbox').removeAttr('checked'); } </code></pre> <p>});</p>
 

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