Skip to content

Instantly share code, notes, and snippets.

@Lobstrosity
Created August 10, 2011 00:35
Show Gist options
  • Save Lobstrosity/1135651 to your computer and use it in GitHub Desktop.
Save Lobstrosity/1135651 to your computer and use it in GitHub Desktop.
jQuery Plugin Pattern
(function($) {
$.fn.enable = function() {
// Enable each selected element by removing its 'disabled' attribute.
return this.each(function() {
$(this).removeAttr('disabled');
});
};
$.fn.disable = function() {
return this.each(function() {
// Disable each selected element that is a form control by setting
// its 'disabled' attribute.
if ($(this).is(':input')) {
$(this).attr('disabled', 'disabled');
}
});
};
})(jQuery);
$.fn.disable = function() {
return this.filter(':input').each(function() {
$(this).attr('disabled', 'disabled');
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment