The normalize()
method of the Node
interface puts the specified node and all of its sub-tree into a normalized form. In a normalized sub-tree, no text nodes in the sub-tree are empty and there are no adjacent text nodes.
The normalize()
method of the Node
interface puts the specified node and all of its sub-tree into a normalized form. In a normalized sub-tree, no text nodes in the sub-tree are empty and there are no adjacent text nodes.
js
normalize()
None.
None.
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:<br/>"; while (node) { result += `${node.nodeName}: ${node.nodeValue}<br/>`; node = node.nextSibling; } wrapper.normalize(); node = wrapper.firstChild; result += "<br/><br/>After normalization:<br/>"; while (node) { result += `${node.nodeName}: ${node.nodeValue}<br/>`; node = node.nextSibling; } const output = document.getElementById("result"); output.innerHTML = result;
Specification |
---|
DOM Standard # ref-for-dom-node-normalize① |
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
normalize |
1 | 12 | 1 | 9 | ≤12.1 | 1 | 4.4 | 18 | 4 | ≤12.1 | 1 | 1.0 |
Text.splitText()
, its opposite.
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Node/normalize