[thelist] Custom HTML Attributes and W3C

hersho robinzon hershelr at netvision.net.il
Mon May 10 12:14:12 CDT 2004


thelist-bounces at lists.evolt.org wrote:
> This, of course, means that you /could/ in theory create your own
> custom DTD that includes your custom tags.  It seems it would
> be a lot
> of work, however, unless you have a very specific reason to
> need to do
> this.  Browsers, of course, would not support your custom tags.

I asked about custom attributes, not custom tags. Modern browsers actually do appear to support custom attributes, insofar as allowing DOM access to the values of those attributes.

I did just now remember a 'trick' I used elsewhere for just this issue--how to store a non-HTML-standard value within an HTML element:

<tip type="Custom HTML Attributes" author="Hershel Robinson">
If you need to associate custom data with an HTML element but you do not want to use a custom attribute which would forego HTML validity, one option is to find a valid attribute that you do not use and that you expect/hope never to use. There are some slightly odd or rarely used ones out there, such as onmousemove and lang (lang is not generally relevant for elements aside from <body>, especially for a single-language document.)

You need only then to assign your custom value to this attribute. The value is then accessible via DOM.

One caveat is that this 'trick' is certainly just that, a trick and it is potentially prone to causing problems in the future, should that attribute one day become relevant.
</tip>

Hershel





More information about the thelist mailing list