get-attrs

0.0.1 • Public • Published

Get Attributes

Get all attributes from a DOM element.

Install

npm install get-attrs

Usage

Doing this:

const getAttrs = require('get-attrs')

const el = document.querySelector('svg')
const attrs = getAttrs(el)

console.log(attrs)

with this:

<svg xmlns="http://www.w3.org/2000/svg" width="256" height="312" viewBox="0 0 256 312"
     id="myId" data-float="1.234" onload="startAnimation('fast')" unquoted=d/\nger!></svg>
  ...
</svg>

makes this:

{
  xmlns: "http://www.w3.org/2000/svg",
  width: 256,
  height: 312,
  viewBox: "0 0 256 312",
  id: "myId",
  data-float: 1.234,
  onload: "startAnimation('fast')",
  unquoted: "d/\nger!"
}

Readme

Keywords

none

Package Sidebar

Install

npm i get-attrs

Weekly Downloads

2

Version

0.0.1

License

MIT

Last publish

Collaborators

  • chrstphrknwtn