Get all links from document using JavaScript

The links collection returns a collection of all elements and with a href attribute in the document. - If element is missing the href attribute then element will be excluded from the collection.
- Type of document.links is object

Example: If document contains 10 links with href tag then  document.links.length will return number 10.
You can get the URL of the first link using index 0 in document.links[0].href

To get all links from the document use the following JavaScript Code:

Hi! I am Sartaj Husain. I am a Professional Software Developer, live in Delhi. I write blogs in my free time. I love to learn and share the knowledge with others because it is no good to try to stop knowledge from going forward. So free posts and tutorials. more..

No comments