Document getElementsByTagName() Method - Find out how many <li> elements there are in the document - Javascript DOM

Javascript examples for DOM:Document getElementsByTagName

Description

Document getElementsByTagName() Method - Find out how many <li> elements there are in the document

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p>An unordered list:</p>
<ul>
  <li>A</li>
  <li>B</li>
  <li>C</li>
</ul>//  w w  w . j  av a2 s  .  c  o  m

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

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

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

</body>
</html>

Related Tutorials