How to define the number of nodes in a node list with JavaScript HTML DOM?

JavascriptObject Oriented ProgrammingFront End Technology

To define the number of nodes in a node list, use the length property.

Example

You can try to run the following code to learn how to implement length property in JavaScript −

<!DOCTYPE html>
<html>
   <body>
      <p>Demo Text1</p>
      <p id = "pid"></p>

      <script>
         var myLen = document.querySelectorAll("p");
         document.getElementById("pid").innerHTML = "This document has " + myLen.length + " paragraph tags.";
      </script>
   </body>
</html>
raja
Published on 27-Feb-2018 11:48:09
Advertisements