Question: Question:
In HTML5 data- * attribute
- data- followed by at least one character
- Must be XML-compatible
- Do not contain ASCII capital letters
Is requesting three
The data-1 attribute of <div data-1="1"></div>
satisfies all the above three, so I think it is HTML valid, but is it correct?
Answer: Answer:
There is no mistake.
It's readable by the standard, and the dataset's setter algorithm doesn't error names that start with a number. The code below works on Chrome, Edge, Firefox and Safari.
document.body.dataset['012'] = 'value';
alert(document.body.getAttribute('data-012'));
However, if you start with a number, dot format access will not be possible.
document.body.dataset.012 = 'value'; // SyntaxError