Skip to content

Instantly share code, notes, and snippets.

@davidpadbury
Created May 11, 2011 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidpadbury/966330 to your computer and use it in GitHub Desktop.
Save davidpadbury/966330 to your computer and use it in GitHub Desktop.
(function($) {
$.fn.limit = function( n, callback ) {
callback = typeof( callback ) === 'function' ? callback : $.noop;
var elements = this;
return elements.click( function(e) {
var checkedCount = elements.filter(':checked').length;
if (checkedCount > n && !callback(checkedCount)) {
e.preventDefault();
}
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment