Skip to content

Instantly share code, notes, and snippets.

@craigh411
Created March 20, 2016 15:50
Show Gist options
  • Save craigh411/4e46072622ae9ef1dd43 to your computer and use it in GitHub Desktop.
Save craigh411/4e46072622ae9ef1dd43 to your computer and use it in GitHub Desktop.

Simple jQuery plugin for checking all checkboxes on a page by a given class name.

Usage

HTML

<input type="checkbox" id="checkAll" />

<input type="checkbox" class="checkMe" />
<input type="checkbox" class="checkMe" />
<input type="checkbox" class="checkMe" />

JQuery

<script type="text/javascript">
  $('#checkAll').checkAll({
  'class' : '.checkMe'
  });
</script>
(function ($) {
$.fn.checkAll = function (options) {
var settings = $.extend({
class: 'input'
}, options);
this.on('click', function () {
$(settings.class + ":checkbox").prop('checked', $(this).prop("checked"));
});
return this;
};
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment