Skip to content

Instantly share code, notes, and snippets.

@duzun

duzun/jq.fn.disEnAble.js

Last active Aug 29, 2015
Embed
What would you like to do?
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