English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
element.tagName
var x = document.getElementById("myPara").tagName;Test See‹/›
The tag name property is fully supported by all browsers:
Property | |||||
tagName | Is | Is | Is | Is | Is |
Return Value: | A String string representing the uppercase tag name of the element |
---|---|
DOM Version: | DOM Level1 |
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‹/›
HTML DOM Reference:node.nodeName property