Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

data-attributes

rafaelrinaldi913MIT1.0.0

Extract data attributes from a DOM node.

data, attribute, attributes, data-attribute, data-attributes, jquery, dom, html, markup, extract, parse, node, element

readme

data-attributes Build Status

Extract data attributes from a DOM node.

Follows the data-* spec.

Install

Via npm:

$ npm install data-attributes --save

Via Bower:

$ bower install data-attributes --save

Usage

<button data-loading-label="Loading..." data-color="#F06">Click me</button>

<script>
  var button = document.querySelector('button');
  var data = dataAttributes(button);

  data(button); // {loadingLabel: "Loading...", color: "#F06"}
</script>

API

dataAttributes(element)

Returns an object containing all data attributes (with camel case keys) from a given DOM node.

Motivation

I needed something like jQuery's $.data() to simply retrieve data attributes from DOM elements. It was for a very old project that needs to support IE7.

If you do not care about IE7, you can simply use dataset.

License

MIT © Rafael Rinaldi

changelog

v1.0.0 (2015/08/17)

  • Initial release.