JavaScript Tutorial/HTML Tags/Anchor
Anchor
An instance of the Anchor object is created with each instance of the <a> tag with the NAME attribute set. An anchor itself is a point in an HTML document that can be reached by using a hypertext link. Anchors allow access to specific parts of Web pages rather than always displaying the top of a document when a Web page is loaded in a browser.
Properties Description name A name that provides access to the anchor from a link text The text that appears between the <a> and </a> tags x The x-coordinate of the anchor y The y-coordinate of the anchor
The following example creates Anchors in a Document.
<source lang="javascript">
<html>
Pick a letter: <a href="#A">A</a>|<a href="#B">B</a>|<a href="#C">C</a>
<a name="A">
The Letter A
</a>A
B
<a name="B"></a>
C
D
F
C
D
F
C
D
F
C
D
F
C
D
F
C
D
F
C
D
F
C
D
F
C
D
F
C
D
F
C
D
F
C
D
F
C
D
F
C
D
F
C
D
F
C
D
F
C
D
F
C
D
F
C
D
F
<a name="C"></a>
G
H
<script language="JavaScript"> </script> </html></source>
Anchor.name
Syntax
<source lang="javascript">
document.anchors[num].name</source>
Anchor.text
Syntax
<source lang="javascript">
document.anchors[num].text</source>
Anchor.x
Syntax
<source lang="javascript">
document.anchors[num].x</source>
Anchor.y
Syntax
<source lang="javascript">
document.anchors[num].y</source>