devxlogo

Use Data Attributes on Elements in HTML5 to Store Data

Use Data Attributes on Elements in HTML5 to Store Data

We can store data in the elements through HTML5’s data attributes. See below for an example on how to store and retrieve data from the data attributes.

The values are added to the anchor element through the data-value and data-options attributes. This is how you access the values:

alert('The ' + $("#elink").data("value") + ' name is ' + $("#elink").data("options").cn);
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist