Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Based on your code, I would add a wrapper around the check-box you want to select all/none and then give the wrapper id and inputs to select all or none.</p> <p><code>$('#list input[type="checkbox"]').attr('checked', false);</code></p> <p>or for jQuery 1.6+</p> <p><code>$('#list input[type="checkbox"]').prop('checked', false);</code></p> <p>This way, you can control all your checkboxes without affecting the "master" one.</p> <p>Here's the code:</p> <pre><code>&lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function() { $('#checkAll').click(function() { if(!$('#master').is(':checked')) { return; } $('#list input[type="checkbox"]').attr('checked', true); }); $('#checkNone').click(function() { $('#list input[type="checkbox"]').attr('checked', false); }); $('#master').click(function() { if($('#master').is(':checked')) { return; } $('#list input[type="checkbox"]').attr('checked', false); }); $('#list input[type="checkbox"]').click(function() { if(!$('#master').is(':checked')) { $(this).attr('checked', false); } }); }); &lt;/script&gt; &lt;/head&gt; &lt;input type="checkbox" value="master" id="master"&gt;master &lt;span id="checkAll"&gt;All&lt;/span&gt; &lt;span id="checkNone"&gt;None&lt;/span&gt; &lt;div id="list"&gt; &lt;input type="checkbox" value="1"&gt;1 &lt;input type="checkbox" value="2"&gt;2 &lt;input type="checkbox" value="3"&gt;3 &lt;input type="checkbox" value="4"&gt;4 &lt;input type="checkbox" value="5"&gt;5 &lt;/div&gt; </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