Use the document.links property in JavaScript to get the number of links in a document. These links can be from <area> and <a> i.e. tags with href attribute.
Example
You can try to run the following code to implement document.links property in JavaScript.
<!DOCTYPE html> <html> <head> <title>JavaScript Example</title> </head> <body> <p> <a href="/java/index.htm">Java</a><br> <a href="/php/index.htm">PHP</a><br> <a href="/ruby/index.htm">Ruby</a><br> <a href="/wordpress/index.htm">WordPress</a> </p> <script> var num = document.links.length; document.write("How many links? "+num); </script> </body> </html>