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

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

Hope this clarifies the picture a bit.

Best,

Tobie





--~--~---------~--~----~------------~-------~--~----~
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 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to