Open In App
Related Articles

HTML DOM normalizeDocument() Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report
The normalizeDocument() method in HTML is used to normalize an HTML document by remove any empty text nodes if exists. After removing the empty nodes, it also merges all of the adjacent nodes present in the document. For Example, consider the below element:
Element Geeks
    Text node: ""
    Text node: "Hello "
    Text node: "wor"
    Text node: "ld"
The above element after normalization will become “Hello world”. Note:This method is not supported by any browser, but it works as DOM normalize() Method and Display the output. Syntax:
geeknode.normalize()
Parameters:
  • The normalize() method does not require any parameter.
  • Example:
    <!DOCTYPE html>
    <html>
      
    <head>
        <meta http-equiv="Content-Type" 
         content="text/html; charset=utf-8" />
        <title>GeeksForGeeks | HTML DOM Normalize Method</title>
    </head>
      
    <body>
        <script type="text/javascript">
            var parent = document.createElement("div");
            parent.appendChild(document.createTextNode("Child 1 "));
            parent.appendChild(document.createTextNode("Child 2 "));
            parent.appendChild(document.createTextNode("Child 3"));
            
            // Here the length of parent's child nodes would be 3, 
            // you can check the same
            // using parent.childNodes.length. 
            alert('Before Normalize : child nodes length: ' + 
                  parent.childNodes.length);
            parent.normalize();
            document.body.appendChild(parent);
            
            // Now, parent.childNodes.length === 1
            // Content of all 3 childs nodes
            // are in one child node only.
            alert('After Normalize : child nodes length: ' + 
                  parent.childNodes.length);
        </script>
    </body>
      
    </html>
    
                        
    Output : Before Normalize() call: After Normalize() call: Supported Browsers: The major browsers are not supported by DOM normalizeDocument() Method

    Last Updated : 13 Jun, 2023
    Like Article
    Save Article
    Previous
    Next
    Share your thoughts in the comments
    Similar Reads