Last active
August 29, 2015 14:08
-
-
Save duzun/b49fb4ece4aeda44b4d5 to your computer and use it in GitHub Desktop.
jQuery.fn.getAttributes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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