Re: Attributes and "Expandos"

I used some unclear language here, so clarifying a bit.

On Jun 22, 2007, at 11:43 AM, Maciej Stachowiak wrote:

>
> On Jun 22, 2007, at 10:12 AM, Travis Leithead wrote:
>
>> Using HTML5 terminology: Current browsers today put all unknown  
>> content attributes (namespace, name and value) into the DOM and  
>> can be [case insensitively] retrieved via getAttribute[NS] and  
>> getAttributeNode[NS], set via setAttribute[NS] and setAttributeNode 
>> [NS], and removed via removeAttribute[NS] and removeAttributeNode.
>>
>> IE, has the concept of “expandos”, meaning it also creates  
>> reflecting DOM attributes on the corresponding element for unknown  
>> content attributes (case-sensitive). Obviously HTML5 does not  
>> define DOM attributes for unknown content attributes, however is  
>> there any general guidelines for reflecting (or not) unknown  
>> content attributes in the DOM, or is that left to the UA’s  
>> discretion?
>
> HTML5 doesn't have a requirement forbidding any kind of additional  
> attributes. However, some aspects of IE's DOM reflection are  
> problematic, and it would be better to treat the DOM element JS  
> attribute namespace as separate from the attribute namespace.

This would be better stated as "... treat the DOM element JS  
*property* namespace as separate from the markup attribute namespace  
as exposed by getAttribute and related."


> I think the following two aspects are non-conforming, although  
> mainly to DOM Core rather than to HTML5:
>
> 1) getAttribute sometimes returns a non-string, for standard  
> attributes that have corresponding non-string DOM attributes. For  
> example getAttribute("onclick").
> 2) Setting a custom property on an element results in an attribute  
> on the element that is visible to getAttribute and serialized via  
> innerHTML.
>
> I don't think adding a custom property for a nonstandard attribute  
> is nonconforming to anything, but is likely to cause compatibility  
> problems with scripts as the language evolves and is probably more  
> confusing than helpful if you fix issues 1 and 2.
>
> Other browsers generally don't have this IE-specific quirk.
>
> Regards,
> Maciej
>
>>
>> ---
>> <body onload="check()">
>>  <a href="foo.html" myExpando="bar">
>>  <script type=text/javascript>
>>  function check()
>>  {
>>                 var anchor = document.getElementsByTagName 
>> ('a').item(0);
>>
>>                 alert("Is a reflecting DOM attribute dynamically  
>> created? (case-insensitive) anchor.myexpando {" + anchor.myexpando  
>> + "}\n" +
>>                       "Is a reflecting DOM attribute dynamically  
>> created? (case-sensitive) anchor.myExpando {" + anchor.myExpando +  
>> "}\n" +
>>                       "Is a content attribute created? (case- 
>> insensitive) anchor.getAttribute('myexpando') {" +  
>> anchor.getAttribute('myexpando') + "}\n" +
>>                       "Is a content attribute created? (case- 
>> sensitive) anchor.getAttribute('myExpando') {" +  
>> anchor.getAttribute('myExpando') + "}");
>>
>>                 // Setting the anchor.myExpando reflects in the
>> // content attribute, and removing the content
>> // attribute removes the DOM attribute.
>>  }
>>  </script>
>

Received on Friday, 22 June 2007 19:55:56 UTC