DOM Properties

Document.links

Returns a live collection of a and area elements with href attributes. Anchors without href and stylesheet link elements are excluded. The presence of href determines membership; the collection does not prove a destination exists. Use it for inspection or link inventories rather than for finding every reference to an external asset. Example result: 1.

Formal Syntax & Structure

html syntaxhtml
document.links

Return Value

HTMLCollection

Live HTMLCollection of qualifying a and area elements.

Working Example

Example Snippethtml
<a href="#intro">Intro</a><a>Placeholder</a><p>  Result:  <output id="result"></output></p><script>  const result = document.getElementById("result");  (async () => {  result.textContent = document.links.length;  })().catch(error => { result.textContent = "Error: " + error.name; });</script>
HTML Reference