Skip to content

Instantly share code, notes, and snippets.

@nash403
Created January 25, 2018 21:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nash403/5544c70fd9e8027e248239a0ef61a670 to your computer and use it in GitHub Desktop.
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)
function getAttributes (el) {
return Array.from(el.attributes)
.map(a => [a.name, a.value])
.reduce((acc, attr) => {
acc[attr[0]] = attr[1]
return acc
}, {})
}
@haydin94
Copy link

Exactly what i need, thank you!

@jdaza33
Copy link

jdaza33 commented Jun 29, 2022

♥♥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment