post icon

Check or Uncheck All Checkboxes with JQuery

If you’re like me, you need to check or uncheck a whole mess of checkboxes on a single page, and you’d prefer to do it fast (rather than click click click ….).

If you don’t already have it, get Firefox with the Firebug addon, click the Firebug icon bottom right, and go to the Console. This is where you can add in JQuery and run it right on the DOM (paste in to the right and click Run).

Use the following to uncheck all that are checked (obviously you don’t need to use the :checked because you don’t need to know if it’s checked or not, but it helps to understand the query structure):

$("input:checked").attr('checked', false);

To check all, change the checked attribute to ‘true’:

$("input:unchecked").attr('checked', true);

If you need to confine to a particular fieldset or div, use a selector in the first part like this:

$("#mydiv input:checked").attr('checked', false);

I hope this helps!

No comments yet.

Leave a comment

Leave a Reply