Ask HN: HTML/JS Standards Question
Nearly everyone (except maybe my coworkers) knows that web standards dictate that lower case HTML tags must always be used. But the question is, why does the JavaScript method .tagName return the object's tag in UPPERCASE?
Good Code:
<div id="welcome">Hello</div>
Bad Code:
<DIV ID="welcome">Hello</DIV>
JavaScript:
document.getElementById("welcome").tagName;
For both, the code would return "DIV" and not "div".
HTML is not necessarily case sensitive, you can use upper or lowercase tags in HTML 5, and perhaps others. With that in mind, the tags should be normalized when querying what an element is (hr == HR == hR == Hr). Uppercase was chosen:
http://www.whatwg.org/specs/web-apps/current-work/multipage/...
"These attributes must return element names converted to ASCII uppercase, regardless of the case with which they were created."
.tagName evaluates to the name of the HTML 4 element, and names are written all-caps in the HTML 4 and older specifications. All-caps is convenient because you can write about, for example, the A element by just typing its name. The standards committees renamed them to lowercase for XHTML and HTML 5, because writing about 'a' elements is ever so much more consistent. Morons.
P.S. In HTML 4 and older, tags are case insensitive. And practical browsers will accept both cases for the foreseeable future.