Skip to content

Instantly share code, notes, and snippets.

@DominicFinn
Created January 30, 2013 17:01
Show Gist options
  • Save DominicFinn/4674680 to your computer and use it in GitHub Desktop.
Save DominicFinn/4674680 to your computer and use it in GitHub Desktop.
A basic check box manager that lets you switch all the checkboxes with a class of 'checkboxElementsClass' on or off.
var checkBoxManager = {
allSelected: false,
checkBoxes: null,
init: function ($checkBoxes) {
var that = this;
that.checkBoxes = $checkBoxes;
},
toggleSelect: function () {
var that = this;
var changeCheckBoxAttribute = function (checked) {
that.checkBoxes.each(function () {
$(this).attr('checked', checked);
});
};
if (that.allSelected) {
changeCheckBoxAttribute(false);
that.allSelected = false;
} else {
changeCheckBoxAttribute(true);
that.allSelected = true;
}
}
}
//example of using
$('document').ready(function () {
checkBoxManager.init($('.checkboxElementsClass'));
$('.selectAllCheckBox').click(function (e) {
checkBoxManager.toggleSelect();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment