Returns the tag name of the element on which it's called. For example, if the element is an <img>
, its 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:
tagName
called on a <div>
element returns "DIV"
."<SomeTag>"
, then the tagName
property's value is "SomeTag"
.For Element
objects, the value of tagName
is the same as the value of the nodeName
property the element object inherits from Node
.
<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.
Specification | Status | Comment |
---|---|---|
Document Object Model (DOM) Level 3 Core Specification The definition of 'Element.tagName' in that specification. | Obsolete | No change |
Document Object Model (DOM) Level 2 Core Specification The definition of 'Element.tagName' in that specification. | Obsolete | Initial definition |
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Feature | Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | ? | (Yes) | ? | ? | ? | ? |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/element/tagName