<html>
<body>
<p id="demo">Click one button to add text, click another button to normalize the document</p>
<button onclick="addTextNode()">Add a Text Node</button>
<button onclick="normPara()">Normalize the Document</button>
<script>
function addTextNode()
{
var y=document.createTextNode(" Click again");
var x=document.getElementById("demo");
x.appendChild(y);
var z=document.getElementById("cc");
z.innerHTML=x.childNodes.length;
}
function normPara()
{
document.normalize();
var x=document.getElementById("demo");
var z=document.getElementById("cc");
z.innerHTML=x.childNodes.length;
}
</script>
<p>The paragraph above has <span id="cc">1</span> child node(s).</p>
</body>
</html>