Skip to content

Instantly share code, notes, and snippets.

@fuddl
Last active December 17, 2015 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fuddl/5633560 to your computer and use it in GitHub Desktop.
Save fuddl/5633560 to your computer and use it in GitHub Desktop.
Uncheck all checkboxes with jQuery
jQuery(':radio').removeAttr('checked');
@yannickoo
Copy link

A non jQuery version:

var checkboxes = document.querySelectorAll('input[type="checkbox"]');

for (var i = 0, j = checkboxes.length; i < j; i++) {
  checkboxes[i].checked = false;
}

@fuddl
Copy link
Author

fuddl commented May 23, 2013

can you make it a one-liner as well?

@Havvy
Copy link

Havvy commented May 23, 2013

document.querySelectorAll('input[type="checkbox"]').forEach(function (cb) { ch.checked = false; });

@yannickoo
Copy link

That won't work because forEach is only available for arrays. Talket with @Havvy and it ended up with:

Array.prototype.forEach.call(document.querySelectorAll('input[type="checkbox"]'),function(a){a.checked=false});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment