data-attributes
v1.0.0
Published
Extract data attributes from a DOM node.
Downloads
506
Maintainers
Readme
data-attributes
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