English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML DOM tagName attribute

HTML DOM Element Object

tagNameThe read-only attribute returns the tag name of the element it calls.

In HTML, the return value of the tag name attribute is always uppercase.

You can also usenodeNameThe attribute returns the tag name of the element. The difference is that nodeName also returns attribute nodes, text nodes, and comment nodes.

Syntax:

element.tagName
var x = document.getElementById("myPara").tagName;
Test See‹/›

Browser Compatibility

The tag name property is fully supported by all browsers:

Property
tagNameIsIsIsIsIs

Technical Details

Return Value:A String string representing the uppercase tag name of the element
DOM Version:DOM Level1

More Examples

Return the tag names of the children of the BODY element:

var x = document.body.children;
var txt = "";
for (let i = 0; i < x.length;++) {
txt +x[i].tagName + "<br>";
}
document.getElementById("para").innerHTML = txt;
Test See‹/›

Use the tag name property with the event.target attribute to find out which factors triggered the specified event:

var x = event.target.tagName;
Test See‹/›

Related References

HTML DOM Reference:node.nodeName property

HTML DOM Element Object