HTML - DOM Document normalizeDocument() Method



HTML DOM document normalizeDocument() method normalize an entire HTML document unlike normalize() method whose scope was limited to node and it's descendants. It removes empty nodes and merges all adjacent nodes in document.

This method is deprecated. Instead of normalizeDocument(), we can use normalize() method.

Syntax

document.normalizeDocument();

Parameter

This method does not take any parameter.

Return Value

This method does not have a return value.

Example of HTML DOM Document 'normalizeDocument()' Method

The normalizeDocument() method is no longer in use. The following example illustrates it's alternative option which is normalize() method.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM Document normalizeDocument() Method
    </title>
</head>
<body>
    <form>
        <fieldset>
            <legend>HTML-DOM-normalize()</legend>
            <input type="text" id="textSelect" placeholder="type here...">
            <input type="button" onclick="makeTextNode()" value="Create Text Node">
            <input type="button" onclick="normalizeDocument()" value="Normalize">
            <div id="appendedNodes">All Text Nodes: </div>
            <div id="divDisplay"></div>
        </fieldset>
    </form>
    <script>
        let divDisplay = document.getElementById("divDisplay");
        let textSelect = document.getElementById("textSelect");
        let appendedNodesDiv = document.getElementById("appendedNodes");
        divDisplay.textContent = 'Total Text Nodes: '
            + appendedNodesDiv.childNodes.length;
        function makeTextNode() {
            let textNode = document.createTextNode(textSelect.value);
            appendedNodesDiv.appendChild(textNode);
            if (textSelect.value === '')
                divDisplay.textContent = 'Empty Text Node Created';
            else
                divDisplay.textContent = 'Text Node Created with value: '
                    + textSelect.value;
            divDisplay.textContent += ', Total Text Nodes: '
                + appendedNodesDiv.childNodes.length;
        }
        function normalizeDocument() {
            appendedNodesDiv.normalize();
            divDisplay.textContent = 'Total Text Nodes: '
                + appendedNodesDiv.childNodes.length;
        }
    </script>
</body>
</html>

Supported Browsers

Method Chrome Edge Firefox Safari Opera
normalizeDocument() No No No No No
html_dom.htm
Advertisements