leongersen / checkboxHelper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

checkboxHelper

jQuery plugin to unify checkbox behaviour across browsers. Based on this jQuery issue and this question on StackOverflow.

For more info on indeterminate checkboxes, see this CSStricks article.

  • Checkboxes go to checked when click in indeterminate state;
  • Checkboxes in indeterminate state fire the change event;
  • Works for mouse and keyboard interactions;

Set a group of checkboxes to any state using the cb helper:

var boxes = $(':checkbox');

boxes.cb('disabled'); // Unchecks, disables all checkboxes;
boxes.cb('indeterminate'); // Sets all checkboxes indeterminate, enabled, checked if required;
boxes.cb('off'); // Uncheckes, enables, all checkboxes;
boxes.cb('checked'); // Checks, enables all checkboxes;

To test the state of a checkbox:

var box = $(':checkbox');

box.cb(':disabled'); // True if disabled;
box.cb(':indeterminate'); // True if indeterminate;
box.cb(':off'); // True if not checked, not indeterminate;
box.cb(':checked'); // True if checked, not indeterminate;

About


Languages

Language:JavaScript 100.0%