I used data-mykey_1 as key, with a value ‘abcd’ . But it was showing undefined only.
It took me some time to figure out , and then I removed the underscore to data-mykey1, to make it work. I am not sure if it’s an issue or intentional though.
Underscores are ok..
- The name of a custom data attribute in HTML begins with
data-
. It must contain only letters, numbers and the following characters: dash (-
), dot (.
), colon (:
), underscore (_
) -- but NOT any ASCII capital letters (A
toZ
).
And works fine my end
let someElement_ = hypeDocument.getElementById('someElement')
console.log(someElement_.dataset.mykey_1);
1 Like