Wednesday, January 9, 2013

Check All Bookmarklet

Here's a bookmarklet for checking or un-checking all check boxes on a web page. It will flip the first check box, then set all the others accordingly.

check!

Here are a couple checkboxes, just to try it:
Here's the code, de-minified:
(function(){
 //all inputs on the page
 var cbs=document.getElementsByTagName('input'); 
 //the value for the checked (true of false)
 var cv;
 //the current checkbox
 var cb;
 
 for(var i in cbs){
  cb=cbs[i];
  if(cb.type=='checkbox'){
   if(cv==null)
    cv = !(cb.checked);
   
   cb.checked=cv;
  }
 }
 
 void(0); //prevent the bookmarklet from switching pages
})() //call the anonymous function


To get this bookmarklet, just drag it to your bookmarks toolbar or your bookmarks area. Click it whenever you want to use it.

No comments: