3 ms·
HTML5 allows "data" attributes: any attribute starting with "data-" can be used for that purpose. Those fields are accessible via node.getAttribute() and also n
by mcav 18y ago
HTML5 allows "data" attributes: any attribute starting with "data-" can be used for that purpose. Those fields are accessible via node.getAttribute() and also node.dataset. But it does not automatically parse JSON.
More info:
http://ejohn.org/blog/html-5-data-attributes/ http://ejohn.org/blog/html-5-data-attributes/
http://ajaxian.com/archives/embed-your-data-in-html-5 http://ajaxian.com/archives/embed-your-data-in-html-5
- sam_in_nyc 18y agoThat doesn't seem like much of an improvement over what already works, other than the namespacing. Is there a reason they chose the attribute "data-whatever" to map to "dataset.whatever" instead of just "data.whatever"? I can create my own attributes, such as _data_id and _data_name, and it's accessible through getAttribute(). It just won't validate, which doesn't bother me too much, since it makes things very convenient. Alas, I'm not here to gripe to you. Is there a way to suggest support for embedding data other than text in attributes? In your experience, are "they" open to new ideas? Is it a time consuming process?
- olavk 18y agoThe "data" prefix is indeed for the sake of namespacing. This is actually quite useful since you can validate and e.g. find typos in ordinary attributes while still having your custom data attributes. If you have some good ideas for HTML5, you just post a well-argued message on the open mailing list (http://www.whatwg.org/mailing-list http://www.whatwg.org/mailing-list), and it will be considered.