Embed data- attribute in HTML 5

Simon Willison over at W3C points out the part of the HTML 5 specficiation that discusses a way to add attributes to HTML elements for your own needs via data-. He says — “this will be incredibly useful for unobtrusive JavaScript where there’s no sensible place to store configuration data as HTML content. It will […]

Share online:

Simon Willison over at W3C points out the part of the HTML 5 specficiation that discusses a way to add attributes to HTML elements for your own needs via data-. He says — “this will be incredibly useful for unobtrusive JavaScript where there’s no sensible place to store configuration data as HTML content. It will also mean Dojo has an approved method for adding custom attributes to declaratively instantiate Dojo widgets.”

Every HTML element may have any number of attributes starting with the string "data-" specified, with any value.

These are intended to store custom data private to the page or application, for which there are no more appropriate attributes or elements.

The dataset DOM attribute provides convenient accessors for all the data-* attributes on an element. On getting, the dataset DOM attribute must return a DOMStringMap object, associated with the following three algorithms, which expose these attributes on their element[…]

About The Author

Deepak Gupta is a IT & Web Consultant. He is the founder and CEO of diTii.com & DIT Technologies, where he's engaged in providing Technology Consultancy, Design and Development of Desktop, Web and Mobile applications using various tools and softwares. Sign-up for the Email for daily updates. Google+ Profile.