aboutsummaryrefslogtreecommitdiff
path: root/files/fr/web/api/document/createtextnode/index.md
blob: 805d83081f3b34eb9fe631ee4f52edd3d879c3cd (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
---
title: document.createTextNode
slug: Web/API/Document/createTextNode
tags:
  - API
  - DOM
  - Méthodes
  - Reference
translation_of: Web/API/Document/createTextNode
---
{{APIRef("DOM")}}

Crée un nouveau nœud de texte.

## Syntaxe

    var text = document.createTextNode(données);

- `texte` est un nœud de texte.
- `donnees` est une chaîne contenant les données à placer dans le nœud de texte.

## Exemple

```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>
```

## Spécifications

| Spécification                                                                                                | Statut                       | Commentaire         |
| ------------------------------------------------------------------------------------------------------------ | ---------------------------- | ------------------- |
| {{SpecName("DOM3 Core", "core.html#ID-1975348127", "Document.createTextNode()")}} | {{Spec2("DOM3 Core")}} | Pas de changement   |
| {{SpecName("DOM2 Core", "core.html#ID-1975348127", "Document.createTextNode()")}} | {{Spec2("DOM2 Core")}} | Définition initiale |

## Compatibilité des navigateurs

{{Compat("api.Document.createTextNode")}}