Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
html要素に設定した属性を全て取得するやつ
(function($, undefined){
/**
* Get all custom attributes
* @param HTMLElement el
* @return Object
*/
$.getAttributes = function(el){
var $el, data, add, i;
$el = $(el);
data = {};
add = function(attr){
if(! attr.nodeValue || $el.attr(attr.name) === undefined){ return; } // For IE7
data[attr.name] = attr.nodeValue;
};
for(i=0; i<el.attributes.length; i++){
add(el.attributes[i]);
}
return data;
};
/**
* jQuery interface
*/
$.fn.attrs = function(){
return $.getAttributes(this.get(0));
};
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.