Open In App

HTML DOM nodeName Property

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. 

Syntax:



document.nodeName

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

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






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

Output:

 

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


Article Tags :