Skip to content

Instantly share code, notes, and snippets.

@nathansmith
Last active March 10, 2019 16:39
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save nathansmith/942659 to your computer and use it in GitHub Desktop.
Save nathansmith/942659 to your computer and use it in GitHub Desktop.
Used to check all checkboxes in a page.
// Paste into Firebug or Chrome Dev Tools console
// when viewing a page with multiple checkboxes.
(function(d) {
var input = d.querySelectorAll('input[type="checkbox"]');
var i = input.length;
while (i--) {
input[i].checked = true;
}
})(this.document);
@mathiasbynens
Copy link

Simply input[i].checked = true would work as well.

Since this is meant to be used in a web inspector thingy, you could use qSA:

[].forEach.call(document.querySelectorAll('input[type="checkbox"]'), function(el) {
  el.checked = true;
});

@okeydoke
Copy link

If you use the Web Developer add on in Firefox under the Forms section you can use Populate Form Fields. Has the added benefit of populating all empty text-fields too.

@kevinSuttle
Copy link

I can't get either one of these scripts to work in Firebug Lite or Chrome's Dev Console. I'm actually trying to do the opposite and uncheck all checkboxes on pages that don't have an check/uncheck all. i.e. Facebook's notification page. http://cl.ly/2R2U1m1w392n2S2K0z3S Any ideas?

@nathansmith
Copy link
Author

@kevinSuttle - This is what you need...

(function(d) {
  var input = d.querySelectorAll('input[type="checkbox"]');
  var i = input.length;

  while (i--) {
    input[i].checked = false;
  }    
})(this.document);

@kevinSuttle
Copy link

ROCK! Thanks Nathan!

@kevinSuttle
Copy link

Just used this on a shady recruiter. The first snippet works best.

@wellington1993
Copy link

Thanks! @nathansmith

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