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 current node. The returned value is 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:
<!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() { var x = document.getElementById("p").nodeName; document.getElementById("p1").innerHTML = x; } </script> </body> </html> |
Output:
Before clicking the button:

After clicking the button:

Supported Browsers: The browser supported by nodeName property are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Recommended Posts:
- HTML | DOM lang Property
- HTML | DOM Style backgroundClip Property
- HTML | DOM Style borderTop Property
- HTML | DOM Meter max Property
- HTML | DOM Input Hidden value Property
- HTML | DOM Textarea autofocus Property
- HTML | DOM Style columnGap Property
- HTML | DOM Input Time autofocus Property
- HTML | DOM Input Submit formTarget Property
- HTML | DOM Style boxSizing Property
- HTML | DOM Video seekable Property
- HTML | DOM Input Checkbox disabled Property
- HTML | DOM Source src Property
- HTML | DOM Input Range max Property
- HTML | DOM Video loop Property
- HTML | DOM Button disabled Property
- HTML | DOM Input URL size Property
- HTML | DOM Style borderImageSource Property
- HTML | DOM Style wordBreak Property
- HTML | DOM Base target Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


