Creates a new Text node.
SyntaxEdit
var text = document.createTextNode(data);
text
is a Text node.data
is a string containing the data to be put in the text node.
ExampleEdit
<!DOCTYPE html>
<html lang="en">
<head>
<title>createTextNode example</title>
<script>
function addTextNode(text) {
var newtext = document.createTextNode(text),
p1 = document.getElementById("p1");
p1.appendChild(newtext);
}
</script>
</head>
<body>
<button onclick="addTextNode('YES! ');">YES!</button>
<button onclick="addTextNode('NO! ');">NO!</button>
<button onclick="addTextNode('WE CAN! ');">WE CAN!</button>
<hr />
<p id="p1">First line of paragraph.</p>
</body>
</html>
SpecificationsEdit
Specification | Status | Comment |
---|---|---|
Document Object Model (DOM) Level 3 Core Specification The definition of 'Document.createTextNode()' in that specification. |
Recommendation | No change |
Document Object Model (DOM) Level 2 Core Specification The definition of 'Document.createTextNode()' in that specification. |
Recommendation | Initial definition |
Browser compatibilityEdit
Document Tags and Contributors
Tags:
Contributors to this page:
teoli,
Sebastianz,
raamdanger,
kscarfone,
ethertank,
Sheppy,
ziyunfei,
Matej Lednar,
Hyeongryeol,
Jabez,
Takenbot,
Ptak82,
BenoitL,
Dria,
JesseW
Last updated by:
teoli,