Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Set a Data Attribute

DOM & Eventsmedium

Course · Section 7: JavaScript in the Browser: DOM and Events · Lecture 76: Selecting and Manipulating Elements

The page has a `<button id='btn'>`. Set its `data-count` attribute to `5` using the dataset API.

Sample tests

Input: dataset.count is '5'
Output: assertion passes

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Dataset values are always strings, so '5' not 5.

Learning resources

  • MDN: HTMLElement.dataset
Approach & explanation (try first)

dataset.count maps to the data-count attribute, stored as a string.

Loading...
⌘/Ctrl + Enter

Run your code to see results.