diff options
| author | Atsuto Yamashita <atyamash@yahoo-corp.jp> | 2022-03-15 19:47:35 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-15 19:47:35 +0900 |
| commit | 9bf38df91fadd199a5ea45ad79d5e111ddfb3fe0 (patch) | |
| tree | 71952407ea41c86feabef4214610d59e15aae55d /files/ja/web/api/node/normalize | |
| parent | c2678137db5f97ad1fe39e872529159a1afafec1 (diff) | |
| parent | 9e7fbb013772ebab9b35185f0d0836995acbe6db (diff) | |
| download | translated-content-9bf38df91fadd199a5ea45ad79d5e111ddfb3fe0.tar.gz translated-content-9bf38df91fadd199a5ea45ad79d5e111ddfb3fe0.tar.bz2 translated-content-9bf38df91fadd199a5ea45ad79d5e111ddfb3fe0.zip | |
Merge branch 'main' into fix-typo-client-side-web-apis-intro-ja
Diffstat (limited to 'files/ja/web/api/node/normalize')
| -rw-r--r-- | files/ja/web/api/node/normalize/index.html | 48 | ||||
| -rw-r--r-- | files/ja/web/api/node/normalize/index.md | 73 |
2 files changed, 73 insertions, 48 deletions
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 ---- -<div>{{ApiRef}}</div> - -<h2 id="Summary" name="Summary">概要</h2> - -<p>指定ノードの空のノードを削除し、隣接するテキストノードをひとつに纏め、文書を「正規化 (normalize)」します。</p> - -<h2 id="Syntax" name="Syntax">構文</h2> - -<pre class="syntaxbox"><em>element</em>.normalize(); -</pre> - -<h2 id="Example" name="Example">例</h2> - -<pre class="brush:js;highlight:10;">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" -</pre> - -<h2 id="Specification" name="Specification">仕様書</h2> - -<ul> - <li><a href="http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-normalize">DOM Level 2 Core: Node.normalize</a></li> -</ul> - -<h2 id="See_also" name="See_also">関連情報</h2> - -<ul> - <li><a href="/ja/docs/Web/API/Text.splitText"><code>Text.splitText</code></a></li> -</ul> 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..7432a8f979 --- /dev/null +++ b/files/ja/web/api/node/normalize/index.md @@ -0,0 +1,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()")}} |
