Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the .tagName DOM property return an uppercase value?

For example, if we have

<html>
    <head>
        <title>FooBar</title>
    </head>
    <body></body>
</html>

If we do document.getElementByTagName("title").TagName, then we will have TITLE (uppercase). While the html standards recommends writing html tags in lowercase.

I know there is no relationship between both, but this still doesn't make sense.

Is there any reason that DOM should return tag names in uppercase?

like image 459
Tamer Shlash Avatar asked Aug 04 '12 19:08

Tamer Shlash


People also ask

Why is tagName capitalized?

Seth Kroger. The older versions of HTML back when JavaScript was first created used all caps for tag names by convention instead of today's lowercase. To stay backwards-compatible with older code tagName() still returns all uppercase and has been stuck that way.

Is tag name case sensitive?

Tag names for HTML elements must exactly match the names of the elements given in the HTML elements section of this document; that is, tag names are case-sensitive.

What is tagName in HTML?

Definition and Usage The tagName property returns the tag name of an element. The tagName property returns the tag name in UPPERCASE. The tagName property is read-only.

What is a tagName?

A tagName is a part of a DOM structure where every element on a page is been defined via tag like input tag, button tag, anchor tag, etc. Each tag has multiple attributes like ID, name, value class, etc.


1 Answers

Technically, this is mandated in DOM Level 1:

The HTML DOM returns the tagName of an HTML element in the canonical uppercase form, regardless of the case in the source HTML document.

The convention of uppercase tag names probably stems from legacy, when HTML was previously developed based on SGML, and element types were declared in uppercase. See this section of the HTML 4.01 spec discussing SGML, HTML and its syntax, as well as for example the HTML 4.01 Strict doctype definition. Any DOM implementations supporting HTML would follow suit.

Note that lowercase tag names are only explicitly required in XHTML (but not XML), and authors are generally recommended to write lowercase tags for easy porting between HTML/XHTML, as well as improving readability. However, this recommendation doesn't occur in the spec; all it says is that tag names are case-insensitive only in HTML as opposed to XHTML and XML.

like image 152
BoltClock Avatar answered Oct 24 '22 03:10

BoltClock