On top of this a simple Java Script API is presented to access these attribute values (in addition to the normal get/set Attribute): property (but it only works as a map of key-value pairs).While no browsers have implemented this exact DOM property, it’s not hugely needed – the above code could be done with the critical line replaced with: I think what is most enticing about this whole specification is that you don’t have to wait for any browser to implement anything in order to begin using it.By starting to use data- prefixes on your HTML metadata today you’ll be safe in knowing that it’ll continue to work well into the future.
A quick example: The above will be perfectly valid HTML 5.
This should be a welcome addition to nearly every Java Script developer.
The question of the best means of attaching raw data to HTML elements – in a valid manner – has been a long-lingering question.
Frameworks have tried to deal with this in different manners, two solutions being: The addition of this prefix completely routes around both issues (including any extra markup for validation or needing to be valid XHTML) with this effective addition.
This article treats an HTML page like a template, with slots where a developer is allowed to put untrusted data.
These slots cover the vast majority of the common places where a developer might want to put untrusted data.
Putting untrusted data in other places in the HTML is not allowed.
A new feature being introduced in HTML 5 is the addition of custom data attributes.
This is a, seemingly, bizarre addition to the specification – but actually provides a number of useful benefits.
Simply, the specification for custom data attributes states that any attribute that starts with “data-” will be treated as a storage area for private data (private in the sense that the end user can’t see it – it doesn’t affect layout or presentation).
This allows you to write valid HTML markup (passing an HTML 5 validator) while, simultaneously, embedding data within your page.