Skip to content

Instantly share code, notes, and snippets.

@westonruter
Created April 30, 2010 16:28
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 westonruter/385435 to your computer and use it in GitHub Desktop.
Save westonruter/385435 to your computer and use it in GitHub Desktop.
jQuery.fn.prop(name, vaue): Same as jQuery('…').attr(name, value) but for DOM attributes (properties)
/**
* Same as jQuery('…').attr(name, value) but for DOM attributes (properties)
* @param {string} name The property name
* @param {mixed} value The property value
* @todo Allow for passing setter
*/
jQuery.fn.prop = function(name, value){
if(typeof value == 'undefined'){
return this.length ? this[0][name] : null;
}
this.each(function(){
this[name] = value;
});
return this;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment