Esta página ha sido traducida del inglés por la comunidad.Aprende más y únete a la comunidad de MDN Web Docs.
Document.createTextNode()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since julio de 2015.
Crea un nuevo nodo de texto. Este método puede ser usado para escapar caracteres HTML.
In this article
Sintaxis
js
var text = document.createTextNode(data);- text es un nodo Text.
- data es una cadena de textostring que contiene los datos a poner en el nodo de texto.
Ejemplo
html
<!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>YES!</button> <button>NO!</button> <button>WE CAN!</button> <hr /> <p>First line of paragraph.</p> </body></html>Especificaciones
| Specification |
|---|
| DOM> # ref-for-dom-document-createtextnode①> |