[whatwg] .localName shouldn't change case
Thomas Broyer
t.broyer at gmail.com
Fri Jun 29 10:22:49 PDT 2007
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 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
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.
--
Thomas Broyer
More information about the whatwg
mailing list