[whatwg] .localName shouldn't change case

Simon Pieters zcorpan at gmail.com
Fri Jun 29 10:35:04 PDT 2007


On Fri, 29 Jun 2007 19:22:49 +0200, Thomas Broyer <t.broyer at gmail.com>  
wrote:

> 2007/6/29, Simon Pieters:
>> For HTML elements in HTML documents, why is Element.localName uppercased
>> for tag names and lowercased for attribute names?
>
> Because of this:
> http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-5353782642
> and this:
> http://www.w3.org/2000/11/DOM-Level-2-errata#html-2

I had hoped that, since .localName doesn't work in IE, that content didn't  
rely on it returning uppercase in HTML (but rather only use it in XML  
contexts).

>> I wouldn't expect it to, and it makes it harder to write scripts that  
>> work for
>> both HTML and XHTML. For example, if you want a script to work in both
>> legacy HTML UAs and HTML5 UAs as well as in XHTML, you may want
>> to do something like if ((elm.tagName == "A" && !elm.namespaceURI) ||
>> (elm.localName == "a" && elm.namespaceURI ==
>> "http://www.w3.org/1999/xhtml")) to check that a given element is an
>> HTML "a" element.
>
> Actually, if you wanted such drastic checks, you'd need yet another
> condition, because HTML5 puts HTML elements in the XHTML namespace:
> http://www.whatwg.org/specs/web-apps/current-work/multipage/section-terminology.html#html-namespace

If .localName didn't return uppercase, then the check would work.

> So I'd just recommend:
> if (elm.localName.lower() == "a") { ... }
>
> or eventually:
> if (elm.localName.lower() == "a"
>     && (!elm.namespaceURI
>         || elm.namespaceURI == "http://www.w3.org/1999/xhtml")) {
>     ....
> }
> if you're working in documents with other namespaces.

Yeah. The case where you have an "A" element in the  
"http://www.w3.org/1999/xhtml" namespace (which isn't an "a" element)  
probably isn't worth worrying about...

-- 
Simon Pieters



More information about the whatwg mailing list