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?
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?
Share Improve this question asked Sep 12, 2016 at 12:15 0xDECAFBAD0xDECAFBAD 6371 gold badge10 silver badges22 bronze badges 1- 1 Can you please post your code? – David R Commented Sep 12, 2016 at 12:16
1 Answer
Reset to default 20The dataset
properties are camel-cased: elem.dataset.childCount
. They are implicitly transformed to hyphenated attribute names (data-child-count
in your case).