MooTools dwCheckboxes Plugin

By  on  

Update / Fix: The checkboxes will no longer toggle when the "mouseup" event doesn't occur on a checkbox.

Every morning I wake up to a bunch of emails in my Gmail inbox that I delete without reading. I end up clicking so many damn checkboxes that my finger damn near falls off. With that in mind, I've created the dwCheckboxes plugin, a MooTools-based class that allows users to click down on a checkbox and drag their mouse over other checkboxes to check or uncheck numerous checkboxes within one click.

The MooTools JavaScript

var dwCheckboxes = new Class({
	Implements: [Options],
	options: {
		elements: 'input[type=checkbox]',	//checkboxes to use
		mode: 'toggle'								//toggle|check|uncheck
	initialize: function(options) {
		//set options
		//prevent drag start in IE
		document.ondragstart = function () { return false; }
		//ensure that the elements are a Element
		this.options.elements = $$(this.options.elements);
		//manage the checkbox actions
	//a method that does whatever should be done
	manage: function() {
		var active = 0;
		this.options.elements.each(function(el) {
				'mousedown': function(e) {
					active = 1;
					el.checked = !el.checked;
				'mouseenter': function(e) {
					if(active === 1) {
						el.checked = ('toggle' == this.options.mode ? !el.checked : 'check' == this.options.mode);
				'click': function(e) {
					el.checked = !el.checked;
					active = 0; 
		var label = $$('label[for=' + el.get('id') + ']');
		if(label.length) {
			label[0].addEvent('click',function() {
				el.checked = !el.checked;
		window.addEvent('mouseup',function() { active = 0; });

There are two options for this mall plugin:

  • elements: the collection of input boxes to apply the plugins for (defaults to all checkboxes).
  • mode: one of three options: toggle, check, or uncheck (defaults to "toggle")

The MooTools Usage

//when the DOM is ready to go
window.addEvent('domready',function() {
	var togglers = new dwCheckboxes({ elements: $$('.toggle'), mode: 'toggle' });
	var checked = new dwCheckboxes({ elements: $$('.checked'), mode: 'check' });
	var unchecked = new dwCheckboxes({ elements: $$('.unchecked'), mode: 'uncheck' });

Recent Features

  • By
    Designing for Simplicity

    Before we get started, it's worth me spending a brief moment introducing myself to you. My name is Mark (or @integralist if Twitter happens to be your communication tool of choice) and I currently work for BBC News in London England as a principal engineer/tech...

  • By
    I’m an Impostor

    This is the hardest thing I've ever had to write, much less admit to myself.  I've written resignation letters from jobs I've loved, I've ended relationships, I've failed at a host of tasks, and let myself down in my life.  All of those feelings were very...

Incredible Demos

  • By
    Simple Image Lazy Load and Fade

    One of the quickest and easiest website performance optimizations is decreasing image loading.  That means a variety of things, including minifying images with tools like ImageOptim and TinyPNG, using data URIs and sprites, and lazy loading images.  It's a bit jarring when you're lazy loading images and they just...

  • By
    Chris Coyier: Some Amazing Work on CodePen III

    I'm back! David asked me to rope up some of my favorite stuff on CodePen again, which I both love doing, and wince at the thought of having to pick so few favorites. I like a ton of stuff on...


  1. Nice work, one problem I see though is that in FF3/Safari 3/Chrome when I click on a checkbox then drag down the list to select more and then release, everytime I mouse over the check boxes in that group they still become checked/unchecked.

    Opera/IE7 look to work as intended.

  2. @Benjamin Sterling: Good catch — I didn’t do a post-mouseup hover when testing the toggle functionality. Looking over the code, I don’t see the issue but I’m going to address it ASAP.

  3. Just an idea. Like setting visibility to layers in photoshop. If you make a first layer visible, then all the other layer that you hover on will get the same state.

    So, difference would be that the toggle would not inverse the state of each and every checkbox but only follow the first state when we clicked.

    Example: If 2nd checkbox is checked and others are not. When i click on the first checkbox and drag. I end up with all of them checked but the 2nd one unchecked.

    I hope you understood what i mean, i wanted to make it as short as possible.

  4. Clever. What advantage does this have over shift click?

  5. Now that’s an excellent class!

    Just to note: remove the console.log‘s!

  6. @Ryan: Thanks

    @Benjamin Sterling: Fixed that issue. We’re all good now.

  7. It should work on the labels as well. And there should be a tooltip or something, maybe just a yellow notice box on the side, to alert the user of this, since it’s unexpected behavior.

  8. theBagg

    What would be better would be a noticeable graphical drag and highlight box, that when dragged over labels and checkboxes it performs the function. It took me a while to actually work out you have to hit the checkbox first. Very clever though.

  9. Nice work (as usual).

    1) Regarding the comment above about errant console log statements, might I suggest the Clientcide dbug plugin? It’s super tiny, and it insulates you from accidentally publishing code with log statements. It’s never good to to leave a bunch of log statements in code, but every now and then we all miss one sooner or later. dbug makes these not throw errors in browsers without firebug.

    2) Just a little nit-pick, but its generally considered a convention in JavaScript to use upper case names for any function that is meant to be used as a constructor. I don’t know if you do this elsewhere in your code, but it’s a big help for anyone using your stuff. It’s all too easy to leave off the “new” in front of a function that isn’t.

    Sorry, don’t mean to nag…

  10. @Aaron Newton: Thanks for the tip and thank you for your work with Moo!

  11. adamnfish

    Fredrik Bränström says:

    It should work on the labels as well.

    I agree. That was the first thing i tried and I was surprised when it didn’t work. I rarely click on the actual checkbox unless I’m forced to (if the for attribute isn’t set)

  12. I use prototype, not MooTools. Here is a copy with fewer options, but for prototype.

    Thanks, David.

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!