Skip to content

Instantly share code, notes, and snippets.

@duzun
Last active August 29, 2015 14:09
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 duzun/01e5fbded0b62987d3f6 to your computer and use it in GitHub Desktop.
Save duzun/01e5fbded0b62987d3f6 to your computer and use it in GitHub Desktop.
A small jQuery plugin to enable/disable any form element, and any generic element (with 'disabled' class)
/**
* A small jQuery plugin to enable/disable any form element,
* and any generic element (with 'disabled' class)
*/
;(function (global) {
var $ = global.jQuery || global.Zepto;
$.fn.enable = function (cls) {
var prp = 'disabled';
cls || (cls = prp);
this.attr(prp, null).prop(prp, false).removeClass(cls);
return this;
};
$.fn.disable = function (cls) {
var prp = 'disabled';
cls || (cls = prp);
this.attr(prp, prp).prop(prp, true).addClass(cls);
return this;
};
})(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment