Open In App
Related Articles

HTML DOM nodeName Property

Improve Article
Save Article
Like Article

The nodeName property is used to return the name of the specified node as a string. It returns different values for different nodes such as if the node attributes, then the returned string is the attribute name, or if the node is an element, then the returned string is the tag name. It is a read-only property. 



Return values: This property returns the name of the current node. The returned value is a string.

  • For element nodes, the returned value is the tagname.
  • For attribute nodes, the returned value is the name of the attribute
  • For document, comment, and text nodes, the returned value is “#document”, “#comment” and “#text” respectively.

Example: In this example, we will use the nodeName property


<!DOCTYPE html>
        DOM nodeName Property
<body onload="start ()" style="text-align: center">
    <h1 style="color:green">
        DOM nodeName Property
    <div id="p">
        Click to get the node name of this element.
    <button onclick="geek()">Click me!</button>
    <p id="p1"></p>
        function geek() {
            let x = document.getElementById("p").nodeName;
            document.getElementById("p1").innerHTML = x;



Supported Browsers: The browser supported by nodeName property are listed below:

  • Google Chrome 1 and above
  • Edge 12 and above
  • Internet Explorer 6 and above
  • Firefox 1 and above
  • Opera 12.1 and above
  • Safari 1 and above

Last Updated : 09 Jun, 2023
Like Article
Save Article
Similar Reads
Related Tutorials