You are here: Reference > JavaScript > client-side > HTML DOM > properties > text (script, title, CommentNode, ...)

text property (script, title, CommentNode, ...)

Browser support:
Sets or returns a string that corresponds the contents of the element.
The text property for CommentNode elements is only supported by Internet Explorer. If you need the text content of a CommentNode or TextNode, use the data or nodeValue property.


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

Possible values:

String that sets 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 text property:
    <script type="text/javascript">
        function GetText () {
            var scripts = document.getElementsByTagName ("script");
            alert (scripts[0].text);
    <button onclick="GetText ();">Get the contents of the script tag!</button>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content