Skip to content

Instantly share code, notes, and snippets.

@nidate
Last active August 29, 2015 14:04
Show Gist options
  • Save nidate/b85b0dd641721b8fa6ca to your computer and use it in GitHub Desktop.
Save nidate/b85b0dd641721b8fa6ca to your computer and use it in GitHub Desktop.
DOMの属性値をJavaScriptのオブジェクトにする
// DOM element's attributes to Object
// DOMの属性値は単なる配列ではない。
var attr = Array.prototype.slice.call(elem.attributes).reduce(function(obj,v) {
obj[v.name] = v.value;
return obj;
}, {});
// https://developer.mozilla.org/en-US/docs/Web/API/Node.attributes
// http://davidwalsh.name/javascript-attributes
// http://stackoverflow.com/questions/4215737/convert-array-to-object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment