document.normalize() example
RUN
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <style> #cc { font-size: 20px; color: red; } </style> </head> <body onload="normPara()"> <h4 id="demo">Click button Add a Text Node để thêm một đoạn text vào trang, click button Normalize để loại nối các đoạn text gần kề lại với nhau.</h4> <button onclick="addTextNode()">Add a Text Node</button> <button onclick="normPara()">Normalize</button> <p>The document has <span id="cc">1</span> child node(s).</p> <script> function addTextNode() { var x = document.createTextNode(" Click."); var y = document.body; y.appendChild(x); var x = document.getElementById("cc"); x.innerHTML = y.childNodes.length; console.log(y.childNodes); } function normPara() { document.normalize(); var x = document.body; var y = document.getElementById("cc"); y.innerHTML = x.childNodes.length; console.log(document.body.childNodes); } </script> </body> </html>
PHÓNG TO