--- title: Document.createTextNode() slug: Web/API/Document/createTextNode tags: - API - DOM - Documento - Referencia - createTextNode - metodo translation_of: Web/API/Document/createTextNode --- <div>{{APIRef("DOM")}}</div> <p>Crea un nuevo nodo de texto. Este método puede ser usado para escapar caracteres HTML.</p> <h2 id="Sintaxis">Sintaxis</h2> <pre class="syntaxbox">var <var>text</var> = document.createTextNode(<var>data</var>); </pre> <ul> <li><var>text</var> es un nodo Text.</li> <li><var>data</var> es una cadena de texto <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a> que contiene los datos a poner en el nodo de texto.</li> </ul> <h2 id="Ejemplo">Ejemplo</h2> <pre class="brush: 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 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> </pre> <h2 id="Especificaciones">Especificaciones</h2> <table class="standard-table"> <thead> <tr> <th scope="col">Especificación</th> <th scope="col">Estado</th> <th scope="col">Comentario</th> </tr> </thead> <tbody> <tr> <td>{{SpecName('DOM WHATWG', '#dom-document-createtextnode', 'Document: createTextNode')}}</td> <td>{{Spec2('DOM WHATWG')}}</td> <td> </td> </tr> </tbody> </table> <h2 id="Compatibilidad_con_navegadores">Compatibilidad con navegadores</h2> <p>{{Compat("api.Document.createTextNode")}}</p>