3 ms·
Since you seem to know a lot about HTML5, and I don't have the inclination to browse through and ingest it all, maybe you could answer this: will there be supp
by sam_in_nyc 18y ago
Since you seem to know a lot about HTML5, and I don't have the inclination to browse through and ingest it all, maybe you could answer this: will there be support for defining custom attributes, and will these attributes allowed be JSON objects?
I've often had the need for something like <div params="{..json..}"></div>. Up until now you're left with the choice of on pageload attaching the JSON to some arbitrary property of the DOM object, or reading the attribute and eval'ing it.
"onxyz" attributes are interpreted automatically as JS, albeit they are automatically cast into a function. I'm hoping there's a similar way to define custom attributes and their types.
- mcav 18y agoHTML5 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.