blob: fc1b1488f4cbaff0248567f84e01e6cdb265ea3d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
---
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>
|