You are here: Reference > JavaScript > client-side > HTML DOM > properties > nodeName

nodeName property

Browser support:
Returns the name of the current node.
This property retrieves the tag names in uppercase in HTML and in original case in XML documents. The tagName property can also be used for getting tag names.

Syntax:

object.nodeName;
You can find the related objects in the Supported by objects section below.
This property is read-only.

Possible values:

String that retrieves the name of the node. For element nodes, returns the name of the element. For attribute nodes, returns the name of the attribute. For text nodes, returns the '#text' string constant.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the nodeName property:
<head>
    <script type="text/javascript">
        function GetNodeInfo () {
            var div = document.getElementById ("myDiv");
            var commentNode = div.firstChild;
            var message = "";
            message += "The name of the node: " + commentNode.nodeName + "\n";
            message += "The type of the node: " + commentNode.nodeType + "\n";
            message += "The value of the node: " + commentNode.nodeValue;
            alert (message);
        }
    </script>
</head>
<body>
    <div id="myDiv"><!-- this text is not rendered --></div>
    <button onclick="GetNodeInfo ()">Get node info!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content