Creates a new Text node.
var text = document.createTextNode(data);
<!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>
Specification | Status | Comment |
---|---|---|
DOM The definition of 'Document: createTextNode' in that specification. | Living Standard |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | Yes | Yes | Yes | Yes | Yes | ? |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | Yes | Yes | Yes | Yes | Yes | ? | ? |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/document/createTextNode