← All Exercises
Data Attributes for State
basichtml
Background
Data attributes provide a clean way to pass data from HTML to JavaScript.
Problem
Store configuration data on HTML elements using data-* attributes for JS access.
Input
HTML elements with data
Output
Data accessible via JS
Sample tests
Sample 1
Input: div with data-user-id
Expected: data accessible in JS
Your solution
Learning objective
Learn data attributes and HTML-JS data passing