On Mar 27, 11:43 am, Walter Lee Davis <[email protected]> wrote:
> On Mar 26, 2011, at 9:37 PM, kstubs wrote:
> > Is it bad, or does it make parsing objects unstable if you append
> > custom attributes to an HTML tag?  Lets say I want to keep track of
> > a number, maybe a customers ID, so I do something like:
>
> > var div = new Element('div', {'customerID':1234});

The issues are inadvertent overwriting of HTML attributes (so you
can't just use any attribute name, you have to be careful) and IE's
mishandling of DOM element attributes and properties.

To get consistency across browsers, you have to read the attributes
using getAttribute and set them (using code) with setAttribute.
Because IE munges attributes and properties, you should only ever use
DOM properties for HTML atributes.

So you need to be careful to distinguish between the two and only use
the appropriate method, which is why it is usually suggested to not
use custom attributes and to use a data object instead, that way you
only ever use one method that is consistent for all browsers.


> > which should result in:
> > <div customerID="1234"></div>

"Should" being the operative word. Note that in IE, the div DOM
element will have a property of customerID, but it will not in
Firefox. That sort of inconsistency is why you should avoid custom
attributes and properties.

Perhaps that issue is fixed in IE 9, but it will be a very long time
before you can ignore all other versions of IE on the web.


> HTML5 lets you do this, and pretty much anything else you like, by  
> adding a data- prefix to the attribute name. Have at it.

HTML5 is not a standard, nor is it widely supported yet.


--
Rob

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to