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).

Expandos are properties of the DOM node (that is of the JS object

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.

To illustrate this, consider the following in Firefox:

>>> var div = $$('div')[0];
>>> div.setAttribute('value', 'foo');
>>> div.getAttribute('value');
>>> div.value;
>>> typeof div.value;
>>> var clone = div.cloneNode(true);
>>> clone.getAttribute('value');

>>> div = $$('div')[1];
>>> div.value = 'foo';
>>> div.getAttribute('value');
>>> div.value;
>>> clone = div.cloneNode(true);
>>> clone.value;
>>> typeof clone.value

Of course, the behaviour is different in IE which shares the same
attribute object between cloned nodes(!).

Hope this clarifies the picture a bit.



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