[Wylug-help] extra HTML properties for access by javascript

Smylers Smylers at stripey.com
Thu Feb 4 13:25:07 UTC 2010


Gary Stainburn writes:

> In other words I want to add extra properties to the TR object.  can I
> do it straight from HTML? I want to do something like:
> 
> <TR id="13"  VehID="20">
> 
> so that in javascript I can then read vehID as a property of the TR
> object
> 
> In Mozilla, it just ignores any properties it doesn't expect.

The HTML standard says browsers should ignore unknown attributes.

However, you'll be in trouble if a later version of HTML adds the vehid
attribute, cos then browsers will start doing things with it.

Instead, call your attribute data-vehid.  The data- prefix is introduced
in HTML5, and is reserved for exactly what you're doing -- page-specific
properties.

Smylers
-- 
Watch fiendish TV quiz 'Only Connect' (some questions by me)
Mondays at 20:30 on BBC4, or iPlayer: http://www.bbc.co.uk/programmes/b00lskhg



More information about the Wylug-help mailing list