The goog.dom.dataset Namespace

.get(element, key)

Gets a custom data attribute from an element. The key should be in camelCase format (e.g "keyName" for the "data-key-name" attribute).

element {Element}
DOM node to get the custom data attribute from.
key {string}
Key for the custom data attribute.
returns {?string}
The attribute value, if it exists.

.getAll(element)

Gets all custom data attributes as a string map. The attribute names will be camel cased (e.g., data-foo-bar -> dataset['foobar']). This operation is not safe for attributes having camel-cased names clashing with already existing properties (e.g., data-to-string -> dataset['toString']).

element {!Element}
DOM node to get the data attributes from.
returns {!Object}
The string map containing data attributes and their respective values.

.has(element, key)

Checks whether custom data attribute exists on an element. The key should be in camelCase format (e.g "keyName" for the "data-key-name" attribute).

element {Element}
DOM node to get the custom data attribute from.
key {string}
Key for the custom data attribute.
returns {boolean}
Whether the attibute exists.

.remove(element, key)

Removes a custom data attribute from an element. The key should be in camelCase format (e.g "keyName" for the "data-key-name" attribute).

element {Element}
DOM node to get the custom data attribute from.
key {string}
Key for the custom data attribute.

.set(element, key, value)

Sets a custom data attribute on an element. The key should be in camelCase format (e.g "keyName" for the "data-key-name" attribute).

element {Element}
DOM node to set the custom data attribute on.
key {string}
Key for the custom data attribute.
value {string}
Value for the custom data attribute.