Skip to content

Instantly share code, notes, and snippets.

@jochemstoel
Forked from victorono/attributes.js
Created August 7, 2017 17:36
Show Gist options
  • Save jochemstoel/3ba9598d0032627092975d9d0439491a to your computer and use it in GitHub Desktop.
Save jochemstoel/3ba9598d0032627092975d9d0439491a to your computer and use it in GitHub Desktop.
All attributes element jQuery
(function(old) {
$.fn.attr = function() {
if(arguments.length === 0) {
if(this.length === 0) {
return null;
}
var obj = {};
$.each(this[0].attributes, function() {
if(this.specified) {
obj[this.name] = this.value;
}
});
return obj;
}
return old.apply(this, arguments);
}
})($.fn.attr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment