Languages
[Edit]
EN

JavaScript - find all links on web page

0 points
Created by:
Dollie-Rutledge
806

In this article, we would like to show you how to find all links on web page using JavaScript.

Quick solution:

or:

 

Practical examples

Edit

1. Using document.links property

Edit

In this example, we use document.links property that contains a collection of all <area> elements and <a> elements in a document.

2. Using querySelectorAll() method

Edit

In this example, we use querySelectorAll() method to get the collection of all links (a elements containing href attribute) on the web page.

Note:

The findLinks() function needs to be executed after window load event or at the end of the script to make sure that all items are loaded before the function execution.

 

See also

Edit
  1. JavaScript - find all HTML comments

  2. JavaScript - find all images on web page

  3. JavaScript - get src of all images on web page

References

Edit
  1. Document.links - Web APIs | MDN
  2. Document.querySelectorAll() - Web APIs | MDN

Alternative titles

  1. JavaScript - how to get all links from particular web page?
  2. JavaScript - get all links from web page
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join