W3C home > Mailing lists > Public > www-dom@w3.org > July to September 2011

Re: [DOMCore] default value of id attribute

From: Mounir Lamouri <mounir@lamouri.fr>
Date: Fri, 26 Aug 2011 12:40:59 +0200
Message-ID: <4E57783B.5000401@lamouri.fr>
To: www-dom@w3.org
On 08/25/2011 02:06 AM, David Flanagan wrote:
> DOM Core 5.7 says:
>
>> The id attribute must return the result of invoking getAttribute()
>> with "id" as argument.
>
> And also says:
>
>> The getAttribute(name) method must run these steps:
>>
>> If the context object is in the HTML namespace and its node document
>> is an HTML document, let name be converted to ASCII lowercase.
>>
>> Return the value of the first attribute in the context object's
>> attributes whose qualified name is name, or null otherwise.
>
> So, for a newly created element e, with no "id" content attribute, e.id
> ought to be null.

Exactly.

> But this contradicts HTML 2.8.1:
>> In general, on getting, if the content attribute is not present, the
>> IDL attribute must act as if the content attribute's value is the
>> empty string;
> And it also contradicts the behavior of Firefox, Chrome and Safari (at
> least) in which document.createElement("div").id is "" instead of null.

This is correct too.
You are getting the IDL attribute which follows the last rule you quoted 
which means it has to return the empty string when the content attribute 
is not present (ie. null).
This should return null:
document.createElement("div").getAttribute('id');

Thanks,
--
Mounir
Received on Friday, 26 August 2011 10:40:51 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:14:08 GMT