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 −
<!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>