Get the node name of a <p> element:
The result of x will be:
More "Try it Yourself" examples below.
The nodeName property returns the name of the specified node.
If the node is an element node, the nodeName property will return the tag name.
If the node is an attribute node, the nodeName property will return the name of the attribute.
For other node types, the nodeName property will return different names for different node types.
Tip: You can also use the tagName property to return the tag name of an element. The difference is that tagName only return tag names, while nodeName returns the name of all nodes (tags, attributes, text, comments).
This property is read-only.
Property | |||||
---|---|---|---|---|---|
nodeName | Yes | Yes | Yes | Yes | Yes |
Return Value: |
A String, representing the name of the node.
Possible values:
|
---|---|
DOM Version | Core Level 1 Node Object |
Get the node name of the <body> element:
The result of x will be:
Get the node names of the <body> element's child nodes:
The result of txt will be:
Get the node name, node value and the node type of the <div> element's first child node:
The result of txt will be:
HTML DOM reference: element.tagName Property
HTML DOM reference: node.nodeType Property
HTML DOM reference: node.nodeValue Property
HTML DOM reference: node.childNodes Property