Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DOMException: Invalid property name on dataset

I receive "Uncaught DOMException: Failed to set the 'child-count' property on 'DOMStringMap': 'child-count' is not a valid property name." when the following code is executed:

elem.dataset['child-count'] = "test";

where elem is a HTMLElement.

Thought it is legit to use the '-' character within data-attribute names or am I missing something else?

like image 639
0xDECAFBAD Avatar asked Sep 12 '16 12:09

0xDECAFBAD


1 Answers

The dataset properties are camel-cased: elem.dataset.childCount. They are implicitly transformed to hyphenated attribute names (data-child-count in your case).

like image 58
Bergi Avatar answered Oct 09 '22 02:10

Bergi