blob: 7fc4bfe70179c721ae1371e1f9f6ee4b1475984d (
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
- Méthodes
- Reference
translation_of: Web/API/Document/createTextNode
---
<p>{{APIRef("DOM")}}</p>
<p>Crée un nouveau nœud de texte.</p>
<h2 id="Syntaxe">Syntaxe</h2>
<pre class="syntaxbox"><var>var text</var> = document.createTextNode(<var>données</var>);
</pre>
<ul>
<li><code>texte</code> est un nœud de texte.</li>
<li><code>donnees</code> est une chaîne contenant les données à placer dans le nœud de texte.</li>
</ul>
<h2 id="Exemple">Exemple</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="Sp.C3.A9cification">Spécifications</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Spécification</th>
<th scope="col">Statut</th>
<th scope="col">Commentaire</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName("DOM3 Core", "core.html#ID-1975348127", "Document.createTextNode()")}}</td>
<td>{{Spec2("DOM3 Core")}}</td>
<td>Pas de changement</td>
</tr>
<tr>
<td>{{SpecName("DOM2 Core", "core.html#ID-1975348127", "Document.createTextNode()")}}</td>
<td>{{Spec2("DOM2 Core")}}</td>
<td>Définition initiale</td>
</tr>
</tbody>
</table>
<h2 id="Compatibilité_des_navigateurs">Compatibilité des navigateurs</h2>
<p>{{Compat("api.Document.createTextNode")}}</p>
|