Node: normalize()-Methode

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Die normalize()-Methode des Node-Interfaces bringt den angegebenen Knoten und seinen gesamten Unterbaum in eine normierte Form. In einem normierten Unterbaum sind keine Textknoten leer und es gibt keine angrenzenden Textknoten.

Syntax

js
normalize()

Parameter

Keine.

Rückgabewert

Keine.

Beispiel

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 = "Before normalization:\n";
while (node) {
  result += ` ${node.nodeName}: ${node.nodeValue}\n`;
  node = node.nextSibling;
}

wrapper.normalize();

node = wrapper.firstChild;
result += "\n\nAfter normalization:\n";
while (node) {
  result += ` ${node.nodeName}: ${node.nodeValue}\n`;
  node = node.nextSibling;
}

const output = document.getElementById("result");
output.innerText = result;

Spezifikationen

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

Browser-Kompatibilität

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
normalize

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Siehe auch