You are here: Reference > JavaScript > client-side > HTML DOM > properties > data (comment, CommentNode, TextNode)

data property (comment, CommentNode, TextNode)

Browser support:
Sets or returns the text content of a CommentNode, TextNode or comment element.
The nodeValue property is identical to the data property for the CommentNode and TextNode objects.
In Internet Explorer, you can also use the text property. It is equivalent to the data property for the comment element and returns the text content with comment opener and closer signs for the CommentNode element.

Syntax:

object.data;
You can find the related objects in the Supported by objects section below.
This property is read/write.

Possible values:

String that specifies or retrieves the text content of the object.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the data property:
<head>
    <script type="text/javascript">
        function GetTextOfComment () {
            var container = document.getElementById ("commentContainer");
            var commentNode = container.firstChild;
            alert (commentNode.data);
        }
    </script>
</head>
<body>
    <div id="commentContainer"><!-- this text is not rendered --></div>
    <button onclick="GetTextOfComment ();">Get the text content of a comment.</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content