Element textContent Property - differences between the textContent and innerHTML property: - Javascript DOM

Javascript examples for DOM:Element textContent

Description

Element textContent Property - differences between the textContent and innerHTML property:

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>//www.  j av a2 s  . c  o  m

<button onclick="getText()">Get textContent</button> <button onclick="getHTML()">Get innerHTML</button>

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

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

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

</body>
</html>

Related Tutorials