Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
jQuery.fn.getAttributes
/*
source: http://stackoverflow.com/questions/2048720/get-all-attributes-from-a-html-element-with-javascript-jquery/16935800#16935800
*/
(function($) {
$.fn.getAttributes = function () {
var elem = this,
attr = {};
if(elem && elem.length) $.each(elem.get(0).attributes, function(v,n) {
n = n.nodeName||n.name;
v = elem.attr(n); // relay on $.fn.attr, it makes some filtering and checks
// could use elem.prop(n) here
if(v != undefined && v !== false) attr[n] = v;
});
return attr;
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment