Easy Tutorial
❮ Prop Style Height Prop Style Bordertop ❯

HTML DOM anchors Collection


Definition and Usage

The anchors collection returns an array of all hyperlinks in the current page.

Syntax


Browser Support

All major browsers support the anchors collection.


Examples

Example 1

Return the number of links in the document:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>tutorialpro.org(tutorialpro.org)</title>
</head>
<body>

<a name="html">HTML Tutorial</a><br>
<a name="css">CSS Tutorial</a><br>
<a name="xml">XML Tutorial</a><br>
<a href="/js/">JavaScript Tutorial</a>

<p>Number of anchors:
<script>
document.write(document.anchors.length);
</script></p>

</body>
</html>

Output of the above example:

Example 2

Return the anchor text of the first hyperlink in the document:

Output of the above example:


❮ Prop Style Height Prop Style Bordertop ❯