<html>
<body>
<ul id="myList"><li id="item1">Coffee</li><li id="item2">Tea</li></ul>
<p id="demo">Click the button get the text content of the list element</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
{
var lst=document.getElementById("myList");
var x=document.getElementById("demo");
x.innerHTML=lst.textContent;
}
</script>
<p><strong>Note:</strong> The textContent property is not supported in Internet Explorer 8 and earlier.</p>
<p><strong>Note:</strong> Textual content includes the text of all child nodes as well.</p>
</body>
</html>