aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/api/node/normalize/index.md
blob: 7432a8f979da0b544bb21e401a9a70ca70f6a0b5 (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
---
title: Node.normalize()
slug: Web/API/Node/normalize
tags:
  - メソッド
  - リファレンス
browser-compat: api.Node.normalize
translation_of: Web/API/Node/normalize
---
{{APIRef("DOM")}}

**`normalize()`** は {{domxref("Node")}} インターフェイスのメソッドで、指定されたノードとその下のツリーを*正規化された*形にします。
正規化されたサブツリーでは、サブツリー内に空のテキストノードがなくなり、隣り合うテキストノードがなくなります。

## 構文

```js
normalize();
```

### 引数

なし。

### 返値

なし。

## 例

```html
<output id="result"></output>
```

```js
let wrapper = document.createElement("div");

wrapper.appendChild( document.createTextNode("Part 1 ") );
wrapper.appendChild( document.createTextNode("Part 2 ") );

let node = wrapper.firstChild;
let result = "正規化前:<br/>";
while (node) {
  result += " " + node.nodeName + ": " + node.nodeValue + "<br/>";
  node = node.nextSibling;
}

wrapper.normalize();

node = wrapper.firstChild;
result += "<br/><br/>正規化後:<br/>";
while (node) {
  result += " " + node.nodeName + ": " + node.nodeValue + "<br/>";
  node = node.nextSibling;
}

const output = document.getElementById("result");
output.innerHTML = result;
```

{{ EmbedLiveSample("Example", "100%", "170")}}

## 仕様書

{{Specifications}}

## ブラウザーの互換性

{{Compat}}

## 関連情報

- 逆の操作である {{domxref("Text.splitText()")}}