HTML DOM Element tagName attribute
- Previous page tabIndex
- Next Page textContent
- Go Up One Level HTML DOM Elements Object
Definition and usage
tagName
The attribute returns the tag name of the element.
In HTML,tagName
The return value of the attribute is always in uppercase.
tagName
Attributes are read-only.
See also:
The difference between tagName and nodeName
nodeName
Attributes can also return the tag name of the element.
nodeName
It can also return the names of attribute nodes, text nodes, and comment nodes.
Instance
Example 1
Get the tagName of the "demo" element:
let name = document.getElementById("demo").tagName;
Example 2
Find out which element triggered the event:
const element = event.target; let name = element.tagName;
Syntax
element.tagName
Return value
Type | Description |
---|---|
String | The tag name of the element. |
Browser support
element.tagName
It is a feature of DOM Level 1 (1998).
All browsers fully support it:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | 9-11 | Support | Support | Support | Support |
- Previous page tabIndex
- Next Page textContent
- Go Up One Level HTML DOM Elements Object