Normalizing Nodes

normalize() removes empty nodes, and merges adjacent text nodes.


RESETRUNFULL
Originally <body> has 6 child nodes: 2 <p> nodes, 1 <script> node, and 3 text nodes spacing the elements.

<!DOCTYPE html><html><body>
   <p>A</p>
   <p>B</p>
   <script>
      bd = document.body;
      alert(bd.childNodes.length); // 6
      pb = document.getElementsByTagName('p')[1];
      bd.insertBefore(document.createTextNode('
   '),pb);
      bd.insertBefore(document.createTextNode('
   '),pb);
      bd.appendChild(document.createTextNode(''));
      alert(bd.childNodes.length);  // 9
      bd.normalize();
      alert(bd.childNodes.length);  // 6
      console.log(bd.childNodes);                        // NodeList(6) [text, p, text, p, text, script]
   </script></body></html>