How to find the number of anchors with JavaScript?

HTMLJavascriptProgramming Scripts

To get the number of anchors, use the anchors property.

Example

You can try to run the following code to get the number of anchors with JavaScript −

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <a href="https://www.tutorialspoint.com/php" name="PHP">PHP</a>
      <br>
      <a href="https://www.tutorialspoint.com/java/" name="Java">Java</a>
      <br>
      <a href="https://www.tutorialspoint.com/html5/" name="HTML5">HTML</a>
      <br>
      <a href="https://www.tutorialspoint.com/css/" name="CSS">CSS</a>
      <script>
         var val = document.anchors.length;
         document.write("<br>Number of anchors in the document: "+val);
      </script>
   </body>
</html>
raja
Published on 26-Feb-2018 12:30:02
Advertisements