On Mar 7, 4:29 am, Tobie Langel <tobie.lan...@gmail.com> wrote:
> Hi again, Rob.
> I don't really want to argue over the benefits of attributes versus
> expandos, just wanted to outline that they weren't the same thing
> although the specs mandate a mapping of specified expandos to their
> attribute counterpart for backwards compatibility with DOM 0.
> It is also the case that IE never really figured out the difference
> between attributes and expandos which has added to the confusion.
> In short, attributes are attributes of the HTML element itself, thus
> can only be used to store and retrieve strings (HTML cannot
> distinguish types of attributes).

Strictly, the markup is interpreted by the browser and it does treat
different attribute values differently.  But I get what you are

> Expandos are properties of the DOM node (that is of the JS object
> itself).
> The expando to attribute mapping only works for attributes specified
> in HTML 4.01 spec (also note that expando can be of all the primitive
> JS types, not only string, and that those are also specified) so it
> won't work for custom attributes.

Hence why only DOM properties that map to valid HTML attributes should
be used.  Once that is realised, it follows that they can all be
reliably set using the DOM element property and that get/setAttribute
is only needed for non-valid attributes and for those, only strings
should be used.

> To illustrate this, consider the following in Firefox:
> >>> var div = $$('div')[0];
> >>> div.setAttribute('value', 'foo');
> >>> div.getAttribute('value');
> "foo"
> >>> div.value;
> >>> typeof div.value;
> "undefined"
> >>> var clone = div.cloneNode(true);
> >>> clone.getAttribute('value');
> "foo"
> >>> div = $$('div')[1];
> >>> div.value = 'foo';
> >>> div.getAttribute('value');
> null
> >>> div.value;
> "foo"
> >>> clone = div.cloneNode(true);
> >>> clone.value;
> >>> typeof clone.value
> "undefined"
> Of course, the behaviour is different in IE which shares the same
> attribute object between cloned nodes(!).

I think you agree with me.  The catch-all here is that DOM elements
are host objects and can't be trusted outside their specified
boundaries (and even then there are issues) unless you are dealing
with a specific sub-set of hosts.  Just don't to it.

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 prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to