Wednesday, April 23rd, 2008
Simon Willison pointed out the part of the HTML 5 spec that discusses a way to add attributes to HTML elements for your own needs via data-.
For example, a spaceship for a game:
- <div class="spaceship" data-id="92432"
- data-weapons="laser 2" data-shields="50%"
- data-x="30" data-y="10" data-z="90">
- <button class="fire"
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:
Posted by Dion Almaer at 7:55 am