Last active
August 29, 2015 14:04
-
-
Save nidate/b85b0dd641721b8fa6ca to your computer and use it in GitHub Desktop.
DOMの属性値をJavaScriptのオブジェクトにする
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
// 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