From 5fbfeee5908241590dacb0f0aac3859f61360947 Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Sun, 27 Feb 2022 13:04:02 +0900 Subject: Node インターフェイスのメソッドの記事を移行 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- files/ja/web/api/node/normalize/index.html | 48 ------------------------------ files/ja/web/api/node/normalize/index.md | 48 ++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 48 deletions(-) delete mode 100644 files/ja/web/api/node/normalize/index.html create mode 100644 files/ja/web/api/node/normalize/index.md (limited to 'files/ja/web/api/node/normalize') diff --git a/files/ja/web/api/node/normalize/index.html b/files/ja/web/api/node/normalize/index.html deleted file mode 100644 index 83026ac378..0000000000 --- a/files/ja/web/api/node/normalize/index.html +++ /dev/null @@ -1,48 +0,0 @@ ---- -title: Node.normalize -slug: Web/API/Node/normalize -tags: - - DOM - - Gecko - - Node -translation_of: Web/API/Node/normalize ---- -
{{ApiRef}}
- -

概要

- -

指定ノードの空のノードを削除し、隣接するテキストノードをひとつに纏め、文書を「正規化 (normalize)」します。

- -

構文

- -
element.normalize();
-
- -

- -
var wrapper = document.createElement("div");
-
-wrapper.appendChild( document.createTextNode("Part 1 ") );
-wrapper.appendChild( document.createTextNode("Part 2 ") );
-
-// wrapper.childNodes[0].textContent === "Part 1 "
-// wrapper.childNodes[1].textContent === "Part 2 "
-// この時点で、wrapper の 子ノード数は 2 です。 wrapper.childNodes.length === 2
-
-wrapper.normalize(); // 正規化
-
-// 正規化後の wrapper の子ノード数は 1 となっています。 wrapper.childNodes.length === 1
-// 挿入処理の為に冗長化したノードはひとつに纏められています。 wrapper.childNodes[0].textContent === "Part 1 Part 2"
-
- -

仕様書

- - - -

関連情報

- - diff --git a/files/ja/web/api/node/normalize/index.md b/files/ja/web/api/node/normalize/index.md new file mode 100644 index 0000000000..83026ac378 --- /dev/null +++ b/files/ja/web/api/node/normalize/index.md @@ -0,0 +1,48 @@ +--- +title: Node.normalize +slug: Web/API/Node/normalize +tags: + - DOM + - Gecko + - Node +translation_of: Web/API/Node/normalize +--- +
{{ApiRef}}
+ +

概要

+ +

指定ノードの空のノードを削除し、隣接するテキストノードをひとつに纏め、文書を「正規化 (normalize)」します。

+ +

構文

+ +
element.normalize();
+
+ +

+ +
var wrapper = document.createElement("div");
+
+wrapper.appendChild( document.createTextNode("Part 1 ") );
+wrapper.appendChild( document.createTextNode("Part 2 ") );
+
+// wrapper.childNodes[0].textContent === "Part 1 "
+// wrapper.childNodes[1].textContent === "Part 2 "
+// この時点で、wrapper の 子ノード数は 2 です。 wrapper.childNodes.length === 2
+
+wrapper.normalize(); // 正規化
+
+// 正規化後の wrapper の子ノード数は 1 となっています。 wrapper.childNodes.length === 1
+// 挿入処理の為に冗長化したノードはひとつに纏められています。 wrapper.childNodes[0].textContent === "Part 1 Part 2"
+
+ +

仕様書

+ + + +

関連情報

+ + -- cgit v1.2.3-54-g00ecf From dd0a249a5aca733d09f33a10b32e20e435a99da9 Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Sun, 27 Feb 2022 17:35:44 +0900 Subject: 2022/01/23 時点の英語版に同期 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- files/ja/web/api/node/normalize/index.md | 79 +++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 27 deletions(-) (limited to 'files/ja/web/api/node/normalize') diff --git a/files/ja/web/api/node/normalize/index.md b/files/ja/web/api/node/normalize/index.md index 83026ac378..7432a8f979 100644 --- a/files/ja/web/api/node/normalize/index.md +++ b/files/ja/web/api/node/normalize/index.md @@ -1,48 +1,73 @@ --- -title: Node.normalize +title: Node.normalize() slug: Web/API/Node/normalize tags: - - DOM - - Gecko - - Node + - メソッド + - リファレンス +browser-compat: api.Node.normalize translation_of: Web/API/Node/normalize --- -
{{ApiRef}}
+{{APIRef("DOM")}} -

概要

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

指定ノードの空のノードを削除し、隣接するテキストノードをひとつに纏め、文書を「正規化 (normalize)」します。

+## 構文 -

構文

+```js +normalize(); +``` -
element.normalize();
-
+### 引数 -

+なし。 -
var wrapper = document.createElement("div");
+### 返値
+
+なし。
+
+## 例
+
+```html
+
+```
+
+```js
+let wrapper = document.createElement("div");
 
 wrapper.appendChild( document.createTextNode("Part 1 ") );
 wrapper.appendChild( document.createTextNode("Part 2 ") );
 
-// wrapper.childNodes[0].textContent === "Part 1 "
-// wrapper.childNodes[1].textContent === "Part 2 "
-// この時点で、wrapper の 子ノード数は 2 です。 wrapper.childNodes.length === 2
+let node = wrapper.firstChild;
+let result = "正規化前:
"; +while (node) { + result += " " + node.nodeName + ": " + node.nodeValue + "
"; + node = node.nextSibling; +} + +wrapper.normalize(); + +node = wrapper.firstChild; +result += "

正規化後:
"; +while (node) { + result += " " + node.nodeName + ": " + node.nodeValue + "
"; + node = node.nextSibling; +} + +const output = document.getElementById("result"); +output.innerHTML = result; +``` + +{{ EmbedLiveSample("Example", "100%", "170")}} -wrapper.normalize(); // 正規化 +## 仕様書 -// 正規化後の wrapper の子ノード数は 1 となっています。 wrapper.childNodes.length === 1 -// 挿入処理の為に冗長化したノードはひとつに纏められています。 wrapper.childNodes[0].textContent === "Part 1 Part 2" -
+{{Specifications}} -

仕様書

+## ブラウザーの互換性 - +{{Compat}} -

関連情報

+## 関連情報 - +- 逆の操作である {{domxref("Text.splitText()")}} -- cgit v1.2.3-54-g00ecf