tagName read-only property of the
Element interface returns the tag name of the element on which it's called. For example, if the element is an
tagName property is
"IMG" (for HTML documents; it may be cased differently for XML/XHTML documents).
elementName = Element.tagName;
A string indicating the element's tag name. This string's capitalization depends on the document type:
- For DOM trees which represent HTML documents, the returned tag name is always in the canonical upper-case form. For example,
tagNamecalled on a
- The tag names of elements in an XML DOM tree are returned in the same case in which they're written in the original XML file. If an XML document includes a tag
"<SomeTag>", then the
tagNameproperty's value is
<span id="born">When I was born...</span>
var span = document.getElementById("born"); console.log(span.tagName);
In XHTML (or any other XML format), the original case will be maintained, so
"span" would be output in case the original tag name was created lowercase. In HTML,
"SPAN" would be output instead regardless of the case used while creating the original document.
The definition of 'Element: tagName' in that specification.
|Chrome Full support 43||Edge Full support 12||Firefox Full support Yes||IE Full support Yes||Opera Full support Yes||Safari Full support 6||WebView Android Full support 43||Chrome Android Full support 43||Edge Mobile Full support Yes||Firefox Android Full support Yes||Opera Android Full support Yes||Safari iOS Full support Yes||Samsung Internet Android Full support Yes|
- Full support
- Full support