Q
How should custom data be stored on an HTML element for use by JavaScript?
-
A
With data-* attributes, such as data-station-id="42", read through element.dataset.stationId
-
B
In the class name only
-
C
With any made-up attribute, such as station="42"
-
D
Inside HTML comments
Correct Answer:
A. With data-* attributes, such as data-station-id="42", read through element.dataset.stationId
Explanation:
data-* attributes are valid HTML. Note that dataset converts names from kebab-case to camelCase.