Shim for DOM dataset
$ npm install dataset
To set data-xxx
attribute on node
to 5:
dataset(node, 'xxx', 5);
To retrieve data-xxx
attribute value:
dataset(node, 'xxx');
To remove data-xxx
attribute:
dataset(node).del('xxx');
You can chain your sets
:
dataset(node)
.set('xxx', 5)
.set('foo', 'bongo');
dataset
property on HTML elements and - for performance reasons - this shim only checks for dataset
support once per load using document.head
element to verify the support.MIT