Skip to content

Instantly share code, notes, and snippets.

@xarimanx
Created March 14, 2014 13:00
Show Gist options
  • Save xarimanx/9547229 to your computer and use it in GitHub Desktop.
Save xarimanx/9547229 to your computer and use it in GitHub Desktop.
return all attr from jq object
(function(old) {
jQuery.fn.attr = function() {
if(arguments.length === 0) {
if(this.length === 0) {
return null;
}
var obj = {};
jQuery.each(this[0].attributes, function() {
if(this.specified) {
obj[this.name] = this.value;
}
});
return obj;
}
return old.apply(this, arguments);
};
})(jQuery.fn.attr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment