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.

Example

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

Live Demo

<!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>
raja
Published on 26-Feb-2018 10:25:21
Advertisements