Element textContent Property - Get all the textual content of an <ul> element with id="myList": - Javascript DOM

Javascript examples for DOM:Element textContent

Description

Element textContent Property - Get all the textual content of an <ul> element with id="myList":

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<ul id="myList">
  <li id="item1">Coffee</li>
  <li id="item2">Tea</li>
</ul>//from   ww w  .j  a  va2 s.  c  o m

<button onclick="myFunction()">Test</button>

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

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

</body>
</html>

Related Tutorials