<html>
<body>
<ul id="myList"><li>Coffee</li><li>Tea</li></ul>
<p id="demo">Click the button to see if the list element has any child nodes</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
{
var lst=document.getElementById("myList");
var x=document.getElementById("demo");
x.innerHTML=lst.hasChildNodes();
}
</script>
<p>Try removing the child nodes of the list element, and the result will be <em>false</em> instead of <em>true</em>.</p>
<p><strong>Note:</strong> Whitespace inside a node is considered as text nodes, so if you leave any white space or line feeds inside an element, that element still has child nodes.</p>
</body>
</html>