Document anchors Collection
Document Object
Definition and Usage
The anchors collection returns an array of all the anchors in the current document.
Syntax
document.anchors[].property
Browser Support

The anchors collection is supported in all major browsers.
Examples
Example 1
Return the number of anchors in the document:
<html>
<body>
<a name="html">HTML Tutorial</a><br>
<a name="css">CSS Tutorial</a><br>
<a name="xml">XML Tutorial</a><br>
<p>Number of anchors:
<script>
document.write(document.anchors.length);
</script></p>
</body>
</html>
The output of the code above will be:
Number of anchors: 3
Try it yourself »
Example 2
Return the innerHTML of the first anchor in the document:
<html>
<body>
<a name="html">HTML Tutorial</a><br>
<a name="css">CSS Tutorial</a><br>
<a name="xml">XML Tutorial</a><br>
<p>innerHTML of first anchor:
<script>
document.write(document.anchors[0].innerHTML);
</script></p>
</body>
</html>
The output of the code above will be:
InnerHTML of first anchor: HTML Tutorial
Try it yourself »
Document Object
Thank You For Helping Us!
Your message has been sent to W3Schools.
Close [X]