<!DOCTYPE html>
<html>
<body>
<h1>The Element Object</h1>
<h2>The normalize() Method</h2>
<button onclick="addTextNode()">Add Text</button>
<button onclick="normPara()">Normalize</button>
<p id="demo">Click one buttons to add text to this paragraph, click the other button to normalize the paragraph.</p>
<p>The paragraph above has <b><span id="cc">1</span></b> child node(s).</p>
<script>
function addTextNode() {
const node = document.createTextNode(" Click again.");
const element = document.getElementById("demo");
element.appendChild(node);
countNodes(element);
}
function normPara() {
const element = document.getElementById("demo");
element.normalize();
countNodes(element);
}
function countNodes(element) {
const span = document.getElementById("cc");
span.innerHTML = element.childNodes.length;
}
</script>
</body>
</html>