Skip to content

Using Data Attributes

View on Twitter

💡 Use the data-* naming convention to pass custom data to HTML elements

Then in JavaScript you can access the data through the `dataset` property

A div element inside an HTML page with two custom data attributes: data-country and data-city. We grab the element in JavaScript and access the custom data through the dataset property: document.querySelector('#card').dataset.
You might also like
Practice Algorithms and Data Structures in JavaScript Read tip
What Does This Bash Command Do? Read tip
What Makes a Website Static Read tip