The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
createTextNode method
Creates a text string from the specified value.
![]() |
Syntax
var retval = document.createTextNode(text);Parameters
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:
