[whatwg] .localName shouldn't change case

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:
and this:

> 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:

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

Received on Friday, 29 June 2007 10:22:49 UTC