HTML DOM Element tagName
Examples
Get the tagName of the "demo" element:
let name = document.getElementById("demo").tagName;
Try it Yourself »
Find which element triggered an event:
const element = event.target;
let name = element.tagName;
Try it Yourself »
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.
Difference Between tagName and nodeName
The nodeName
property also returns the tag name of an element.
The nodeName
can also return the tag name of attribute nodes, text nodes, and comment nodes.
See Also:
Syntax
element.tagName
Return Value
Type | Description |
String | The tag name of the element (in uppercase). |
Browser Support
element.tagName
is a DOM Level 1 (1998) feature.
It is fully supported in all browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 9-11 | Yes | Yes | Yes | Yes |