Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
go
Expand Minimize

createTextNode method

Creates a text string from the specified value.

Document Object Model (DOM) Level 3 Core Specification, Section 1.4

 

Syntax

var retval = document.createTextNode(text);

Parameters

text [in, optional]

Type: BSTR

A String that specifies the nodeValue property of the text node.

Return value

Type: IHTMLDOMNode

Returns the created TextNode object.

Standards information

Remarks

This method always returns S_OK, so you must check the returned newTextNode value. If newTextNode is NULL, the method failed to create a new text node.

Examples


<!DOCTYPE html>

<html>
<head>
  <title>createTextNode</title>
</head>
<body>
  <span id="oSpan" onclick="fnChangeNode()">Original Text (click me)</span>
  <script>
    function fnChangeNode() {
      var oTextNode = document.createTextNode("New Text (thanks for the click)");
      var oReplaceNode = document.getElementById('oSpan').childNodes[0];
      oReplaceNode.replaceNode(oTextNode);
    }
  </script>
</body>
</html>

See also

document
Reference
createElement
Conceptual
About the W3C Document Object Model

 

 

Show:
© 2015 Microsoft