How to work with document.links in JavaScript?

HTMLJavascriptProgramming Scripts

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.


You can try to run the following code to implement document.links property in JavaScript.

Live Demo

<!DOCTYPE html>
      <title>JavaScript Example</title>
         <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>
         var num = document.links.length;
         document.write("How many links? "+num);
Updated on 20-May-2020 10:57:18