How to find the number of anchors with JavaScript?

HTMLJavascriptProgramming Scripts

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


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

Live Demo

<!DOCTYPE html>
      <a href="" name="PHP">PHP</a>
      <a href="" name="Java">Java</a>
      <a href="" name="HTML5">HTML</a>
      <a href="" name="CSS">CSS</a>
         var val = document.anchors.length;
         document.write("<br>Number of anchors in the document: "+val);
Updated on 23-Jun-2020 08:34:08