Created
January 25, 2018 21:10
-
-
Save nash403/5544c70fd9e8027e248239a0ef61a670 to your computer and use it in GitHub Desktop.
Get attributes of an HTML element as a JSON Object (not as NamedNodeMap)
This file contains hidden or 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
function getAttributes (el) { | |
return Array.from(el.attributes) | |
.map(a => [a.name, a.value]) | |
.reduce((acc, attr) => { | |
acc[attr[0]] = attr[1] | |
return acc | |
}, {}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Exactly what i need, thank you!