[imps] getAttribute() returning null

Kartikaya Gupta lists.whatwg at stakface.com
Tue Nov 4 21:18:56 PST 2008


Hi,

I was wondering if HTML5 will address the return value of Element.getAttribute() for unknown attributes. The DOM spec [1] says that it should be the empty string but based on some testing it seems like all major browsers will return null if the attribute doesn't have a default/specified value. I dug around a bit and it seems like Opera switched to this behavior in 9.0 (presumably before that it returned the empty string). There's a bug in Bugzilla [2] that covers this case and it seems that the resolution was to change the spec, but I wasn't able to determine if that has happened/is going to happen/got forgotten.

FWIW, as a specific example, Hotmail seems to rely on the null return value in some of its scripts, which is causing us problems since we return the empty string as per the spec. It's (so far) the only website I've run into that has this problem. Personally I prefer the empty string return value since it means fewer if-null checks littering my code :)

Cheers,
kats

[1] http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-666EE0F9
[2] https://bugzilla.mozilla.org/show_bug.cgi?id=108480



More information about the Implementors mailing list