Returns the name of the element.
elementName = element.tagName;
elementName
is a string containing the name of the current element.In XML (and XML-based languages such as XHTML), tagName
preserves case. On HTML elements in DOM trees flagged as HTML documents, tagName
returns the element name in the uppercase form. The value of tagName
is the same as that of nodeName.
<span id="born">When I was born...</span>
var span = document.getElementById("born"); console.log(span.tagName);
In XHTML (or any other XML format), "span"
would be output. In HTML, "SPAN"
would be output instead.
Specification | Status | Comment |
---|---|---|
Document Object Model (DOM) Level 3 Core Specification The definition of 'Element.tagName' in that specification. | Recommendation | No change |
Document Object Model (DOM) Level 2 Core Specification The definition of 'Element.tagName' in that specification. | Recommendation | 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–2017 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