Anchor : Anchor « HTML Tags « JavaScript Tutorial






An instance of the Anchor object is created with each instance of the 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.

PropertiesDescription
nameA name that provides access to the anchor from a link
textThe text that appears between the and tags
xThe x-coordinate of the anchor
yThe y-coordinate of the anchor


The following example creates Anchors in a Document.

<html>
    <center>
    Pick a letter:
    <a href="#A">A</a>|<a href="#B">B</a>|<a href="#C">C</a>
    </center>
    <hr><a name="A"><h4>The Letter A</h4></a>
    A<br>
     B<br>
    <hr><a name="B"></a>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    C<br>
    D<br>
    F<br>
    <hr><a name="C"></a>
    G<br>
    H<br>
    <script language="JavaScript">
    <!--
    document.write("<hr>The Anchor Properties:<br>");

    for(var counter=0; counter<=document.anchors.length; counter++)
    {
      document.write("anchors[",counter,"].name=");

      document.write(document.anchors[counter].name,"<br>");

      document.write("anchors[",counter,"].text=");

      document.write(document.anchors[counter].text,"<br>");

      document.write("anchors[",counter,"].x=");

      document.write(document.anchors[counter].x,"<br>");

      document.write("anchors[",counter,"].y=");

      document.write(document.anchors[counter].y,"<br>");

    }
    -->
    </script>
    </html>








21.2.Anchor
21.2.1.Anchor
21.2.2.Anchor.name
21.2.3.Anchor.text
21.2.4.Anchor.x
21.2.5.Anchor.y