files/en-us/web/api/node/nodename/index.md
{{APIRef("DOM")}}
The read-only nodeName property of {{domxref("Node")}} returns the name of the current node as a string.
A string. Values for the different types of nodes are:
"#cdata-section"."#comment"."#document"."#document-fragment"."#text".This example displays the node names of several nodes
This is some HTML:
<div id="d1">Hello world</div>
<!-- Example of comment -->
Text <span>Text</span> Text
<svg height="20" width="20">
<circle cx="10" cy="10" r="5" stroke="black" stroke-width="1" fill="red" />
</svg>
<hr />
<output id="result">Not calculated yet.</output>
and the following script:
let node = document.querySelector("body").firstChild;
let result = "Node names are:\n";
while (node) {
result += `${node.nodeName}\n`;
node = node.nextSibling;
}
const output = document.getElementById("result");
output.innerText = result;
{{ EmbedLiveSample("Example", "100%", "450")}}
{{Specifications}}
{{Compat}}