- Source:
Methods
removeData(node, propertiesopt) → {*|Object.<String, *>|null}
Removes data from an element, by removing corresponding data-attributes.
This method has a major difference from the standard browser dataset-implementations:
Property names are not handled camel-cased in any way.
The data attribute's my-naughty-dog
property is not magically created from myNaughtyDog
,
but the original notation will be kept, just adding the prefix,
so use my-naughty-dog
to remove data-my-naughty-dog
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
node |
HTMLElement | the element to remove data from |
||
properties |
String | Array.<String> |
<optional> |
null | if set, removes specified property/properties, if left out, all data properties are removed |
- Source:
- See:
Throws:
error if node is not a usable HTML element
Returns:
the removed data values as they would be returned from getData (single value for one property, dictionaries for multiple or all) or null if nothing was removed
- Type
- * | Object.<String, *> | null
Example
const testNode = createNode(`<span data-foobar="test" data-boofar="null" data-baz='{"a" : ["1", 2, 3.3], "b" : true}'></span>`)
removeData(testNode, 'foobar')
=> 'test' (testNode.outerHTML === `<span data-boofar="null" data-baz='{"a" : ["1", 2, 3.3], "b" : true}'></span>`)
removeData(testNode, ['foobar', 'baz', 'test'])
=> {foobar : 'test', baz : {"a" : ["1", 2, 3.3], "b" : true}} (testNode.outerHTML === `<span data-boofar="null"></span>`)
removeData(testNode)
=> {foobar : 'test', boofar : null, baz : {"a" : ["1", 2, 3.3], "b" : true}} (testNode.outerHTML === `<span></span>`)
removeData(testNode, 'test')
=> null