Display the number of links present in a document using JavaScript Last Updated : 07 Jun, 2023 Comments Improve Suggest changes 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 Display the number of links present in a document using JavaScript G geeksforgeeks user Follow Improve Article Tags : JavaScript Similar Reads JavaScript Tutorial JavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.JavaScript on Client Side: On the client side, Jav 11 min read JavaScript Interview Questions and Answers JavaScript (JS) is the most popular lightweight, scripting, and interpreted programming language. JavaScript is well-known as a scripting language for web pages, mobile apps, web servers, and many other platforms. Both front-end and back-end developers need to have a strong command of JavaScript, as 15+ min read Introduction to JavaScript JavaScript is a versatile, dynamically typed programming language used for interactive web applications, supporting both client-side and server-side development, and integrating seamlessly with HTML, CSS, and a rich standard library.JavaScript is a single-threaded language that executes one task at 7 min read JSON Web Token (JWT) A JSON Web Token (JWT) is a standard used to securely transmit information between a client (like a frontend application) and a server (the backend). It is commonly used to verify users' identities, authenticate them, and ensure safe communication between the two. JWTs are mainly used in web apps an 7 min read Frontend Developer Interview Questions and Answers Frontend development is an important part of web applications, and it is used to build dynamic and user-friendly web applications with an interactive user interface (UI). Many companies are hiring skilled Frontend developers with expertise in HTML, CSS, JavaScript, and modern frameworks and librarie 15+ min read JavaScript Coding Questions and Answers JavaScript is the most commonly used interpreted, and scripted Programming language. It is used to make web pages, mobile applications, web servers, and other platforms. Developed in 1995 by Brendan Eich. Developers should have a solid command over this because many job roles need proficiency in Jav 15+ min read Functions in JavaScript Functions in JavaScript are reusable blocks of code designed to perform specific tasks. They allow you to organize, reuse, and modularize code. It can take inputs, perform actions, and return outputs.JavaScriptfunction sum(x, y) { return x + y; } console.log(sum(6, 9));Output15 Function Syntax and W 5 min read Top 95+ Javascript Projects For 2025 JavaScript is a lightweight, cross-platform programming language that powers dynamic and interactive web content. From real-time updates to interactive maps and animations, JavaScript brings web pages to life.Here, we provided 95+ JavaScript projects with source code and ideas to provide hands-on ex 4 min read JavaScript Exercises, Practice Questions and Solutions JavaScript Exercise covers interactive quizzes, tracks progress, and enhances coding skills with our engaging portal. Ideal for beginners and experienced developers, Level up your JavaScript proficiency at your own pace. Start coding now! A step-by-step JavaScript practice guide for beginner to adva 3 min read HTML DOM (Document Object Model) The HTML DOM (Document Object Model) is a programming interface that represents the structure of a web page in a way that programming languages like JavaScript can understand and manipulate. Think of it as a tree of objects where each part of your HTML document (elements, attributes, text) is repres 5 min read Like