Skip to content

Instantly share code, notes, and snippets.

@wtrocki
Created January 12, 2016 14:30
Show Gist options
  • Save wtrocki/4b5005bb211ddf56451d to your computer and use it in GitHub Desktop.
Save wtrocki/4b5005bb211ddf56451d to your computer and use it in GitHub Desktop.
// Common JQuery helper methods
// Author [email protected]
/**
* Mark element as disabled.
* Note: this method is not removing custom events connected to element.
*
* @param disabled boolean - true if element should be disabled
* @returns {$}
*/
$.fn.disableElement = function (disabled){
if (disabled){
// Compatible with XHTML and HTML5
this.attr("disabled", true);
} else{
this.removeAttr('disabled');
}
return this;
};
/**
* Get element disabled state
*
* returns true if element is disabled, false otherwise
*/
$.fn.isDisabled = function (){
return !!this.attr("disabled");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment