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

nodeValue property

Browser support:
Sets or returns the value of the current node.
The attribute.nodeValue, document.nodeValue and the TextNode.nodeValue properties are read/write, all others are read-only.

Syntax:

object.nodeValue;
You can find the related objects in the Supported by objects section below.

Possible values:

The value depends on the type of the node.
The following table contains the possible values:
String, the value of the node
In the case of Attribute nodes. In Internet Explorer, the type of the value can also be Boolean (e.g. checked) and number (e.g. colSpan) and the value is always null for certain event attributes (e.g. onload), regardless of whether it is specified.
String, the contents of the node
In the case of Text, CDATASection and Comment nodes.
String, the entire content excluding the target
In the case of ProcessingInstruction nodes.
null
In the case of Element, Document, DocumentFragment, DocumentType, EntityReference, Entity and Notation nodes.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the nodeValue 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