このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

Node: normalize() メソッド

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015年7月⁩.

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

構文

js
normalize() 

引数

なし。

返値

なし。

html
<output id="result"></output> 
js
const 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; 

仕様書

Specification
DOM
# ref-for-dom-node-normalize①

ブラウザーの互換性

関連情報