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 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.
Before clicking the button:
After clicking the button:
Supported Browsers: The browser supported by nodeName property are listed below:
- Google Chrome
- Internet Explorer