Edit This Code:
<!DOCTYPE html>
<html>
<body>

<ul id="myList">
  <li id="item1">Coffee</li>
  <li id="item2">Tea</li>
</ul>

<p>Click the button get the text content of the ul element.</p>

<button onclick="myFunction()">Try it</button>

<p><strong>Note:</strong> Textual content includes the text of all child nodes as well.</p>

<p><strong>Note:</strong> The textContent property is not supported in Internet Explorer 8 and earlier.</p>

<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myList").textContent;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>


Result:
Try it Yourself - © w3schools.com
Privacy Policy