-
Notifications
You must be signed in to change notification settings - Fork 22.5k
/
index.md
66 lines (47 loc) · 1.17 KB
/
index.md
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
---
title: "Document: createTextNode() method"
short-title: createTextNode()
slug: Web/API/Document/createTextNode
page-type: web-api-instance-method
browser-compat: api.Document.createTextNode
---
{{APIRef("DOM")}}
Creates a new {{domxref("Text")}} node. This method can be used to escape HTML
characters.
## Syntax
```js-nolint
createTextNode(data)
```
### Parameters
- `data`
- : A string containing the data to be put in the text node.
### Return value
A {{domxref("Text")}} node.
## Examples
```html
<!doctype html>
<html lang="en">
<head>
<title>createTextNode example</title>
<script>
function addTextNode(text) {
const newtext = document.createTextNode(text);
const 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>
```
{{EmbedLiveSample('Examples')}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}