Display the number of links present in a document using JavaScript Last Updated : 07 Jun, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report Any webpage that is loaded in the browser can be represented by the Document interface. This serves as an entry point to the DOM tree and the DOM tree contains all elements such as <body> , <title>, <table> ,<a> etc. We can create a Document object using the Document() constructor. There are many properties of these Document objects. One such property is links. The links property gives us a collection of all <area> elements and <a> elements in a document. One more property is the length property. The length property tells us the number of links present in the document.links array. So, the document.links.length statement gives us the number of links present in a document. Below HTML document contains a JavaScript piece of code that tells the number of links present in the document. Example 1: In this example, we will print the count of links on the console. HTML <!DOCTYPE html> <html lang="en"> <head> <title> Display the number of links present in a document using JavaScript </title> </head> <body> <h1 style="color: green;"> GeeksforGeeks </h1> <h3> Display the number of links present in document </h3> <a href="www.geeksforgeeks.org"> GeeksforGeeks Home Page </a> <a href="practice.geeksforgeeks.org"> GeeksforGeeks Practice </a> <script> console.log("Number of links: " + document.links.length); </script> </body> </html> Output: Example 2: In this example, we will print the number of links on the document. HTML <!DOCTYPE html> <html lang="en"> <head> <title> Display the number of links present in a document using JavaScript </title> </head> <body> <h1 style="color: green;"> GeeksforGeeks </h1> <h3> Display the number of links present in document </h3> <p> <a href="www.geeksforgeeks.org"> GeeksforGeeks Home Page </a> </p> <p> <a href="practice.geeksforgeeks.org"> GeeksforGeeks Practice </a> </p> <button onclick="fun()"> Click Here to Get Number of Links </button> <p id="gfg"></p> <script> function fun() { document.getElementById('gfg') .innerHTML = "Number of links: " + document.links.length; } </script> </body> </html> Output: Comment More infoAdvertise with us Next Article How to Return the Number of Images in a Document with JavaScript? GeeksforGeeks Improve Article Tags : JavaScript Similar Reads How to Return the Number of Images in a Document with JavaScript? We will learn how we can return the number of images in a document with JavaScript. We need to access and manipulate the DOM (Document Object Model) of the webpage. The DOM represents the structure of an HTML document as a tree of objects. JavaScript can interact with the DOM to manipulate and retri 3 min read How to count the number of times a button is clicked using JavaScript ? At times, it becomes necessary to monitor the number of times a user clicks a button. In this article, we are going to learn how to count the number of times a button is clicked using JavaScript Below are the approaches to count the number of times a button is clicked using JavaScript Table of Conte 3 min read How to Get the Size of an Array in JavaScript To get the size (or length) of an array in JavaScript, we can use array.length property. The size of array refers to the number of elements present in that array. Syntaxconst a = [ 10, 20, 30, 40, 50 ] let s = a.length; // s => 5 The JavaScript Array Length returns an unsigned integer value that 2 min read How to count all child elements of a particular element using JavaScript ? Given an HTML document containing some elements nested elements and the task is to count all the child elements of a particular element. It is very simple to count the number of child elements of a particular element using JavaScript. For example: If you have a parent element consisting of many chil 1 min read How to Count Number of Rows and Columns in a Table Using jQuery? Given an HTML document containing a table, the task is to count the number of rows and columns in that table using JQuery. There are a few methods available in jQuery to count the number of rows and columns in an HTML table. Table of Content By iterating through the rows and columnsBy using the leng 3 min read How to make a word count in textarea using JavaScript ? Counting words may be useful in scenarios where the user is recommended to enter a certain number of words and the word counter can keep track of the same. Below are approaches to make a word count in textarea using JavaScript:Table of Content Calculating the number of spaces present in the textSepa 4 min read Like