English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The nodeName read-only property returns the name of the current node as a string.
If the node is an element node, the nodeName property will return the tag name in uppercase.
If the node is an attribute node, the nodeName property will return the name of the attribute.
For other node types, the nodeName property will return different names for different node types.
Note:You can also usetagNameAttribute returns the tag name of the element. The difference is that tagName only returns the tag name, while nodeName returns the names of all nodes (tag, attribute, text, comment).
node.nodeName
var x = document.getElementById("myPara").nodeName;Test and See‹/›
nodeName property is fully supported in all browsers:
Attribute | |||||
nodeName | Is | Is | Is | Is | Is |
Return value: | String representing the node name. Possible values:
|
---|---|
DOM version: | DOM level1 |
Return the node names of the child nodes of the BODY element:
var x = document.body.childNodes; var txt = ""; for (let i = 0; i < x.length;++) { txt += x[i].nodeName + "<br>"; } document.getElementById("para").innerHTML = txt;Test and See‹/›
Return the node name, node type, and node value of the first child node of div:
<div id="div-1">This is a div element.</div> <script> var x = document.getElementById("div-1).firstChild; var txt = ""; txt +="Node Name: " + x.nodeName + "<br>"; txt +="Node Value: " + x.nodeValue + "<br>"; txt +="Node Type: " + x.nodeType; document.getElementById("para").innerHTML = txt; </script>Test and See‹/›
HTML DOM Reference:node .childNodes property
HTML DOM Reference:node .firstChild property
HTML DOM Reference:node .lastChild property
HTML DOM Reference:node .parentNode property
HTML DOM Reference:node .previousSibling property
HTML DOM Reference:node .nextSibling property