Skip to content

Instantly share code, notes, and snippets.

@klauskpm
Last active August 29, 2015 14:10
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 klauskpm/732310d0d3e10913162d to your computer and use it in GitHub Desktop.
Save klauskpm/732310d0d3e10913162d to your computer and use it in GitHub Desktop.
Plugin to retrieve all attributes of a element
// jQuery Plugin - Loader
//
// Needs:
// - jQuery(2.1.1) >> http://code.jquery.com/jquery-2.1.1.js
(function($) {
/**
* Plugin to retrieve all attributes of a element
* @returns {Object}
*/
$.fn.attrs = function(){
var attributes = this.prop('attributes'),
retrivedAttributes = {};
for(var x = 0; x<attributes.length; x++) {
retrivedAttributes[attributes[x].name] = attributes[x].value;
}
return retrivedAttributes;
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment