createTextNode
Summary
Creates a text node containing the passed string (nodeValue).
Method of dom/Documentdom/Document
Syntax
var textNode = document.createTextNode(text);
Parameters
text
- Data-type
- String
The nodeValue property of the text node.
Return Value
Returns an object of type DOM NodeDOM Node
The created TextNode.
Examples
<script>
//create a text node and replace an existing node with the new one
function changeNode() {
var textNode = document.createTextNode("New Text");
var replaceNode = document.getElementById("span").childNodes(0);
replaceNode.replaceNode(textNode);
}
</script>
<span id="span" onclick="changeNode()">
Original Text
</span>
Related specifications
- DOM Level 3 Core
- Recommendation
See also
Related pages
Reference
- createElementcreateElement
Conceptual
About the W3C Document Object Model
Attributions
Microsoft Developer Network: [Windows Internet Explorer API reference Article]