JavaScript EditorBest javascript editor debugger     Ajax website 

Main Page

Previous Page
Next Page

Linking to a Specific Anchor

Once you have created an anchor, you can define a link so that a user's click brings them directly to the section of the document that contains the anchor, not just the top of that document.

To create a link to an anchor:

Type <a href="#anchor name">, where anchor name is the value of the name attribute in the destination's a tag (step 2 on page 106) or the value of the destination's id attribute (see first tip on page 106).

Figure 6.9. When the visitor points at a link with an anchor, the URL and the anchor name appear in the status bar (in the lower-left corner of the window).

Type the label text, that is, the text that is highlighted (usually blue and underlined), and that when clicked upon will take the user to the section referenced in step 1.

Type </a> to complete the definition of the link.

Figure 6.10. Once the visitor clicks the link, the particular part of the page that the anchor references is displayed at the top of the browser window.


  • If the anchor is in a separate document, use <a href="page.html#anchorname"> to reference the section. (There should be no space between the URL and the #.) If the anchor is on a page on a different server, you'll have to type <a href="/"> (with no spaces).

  • While you obviously can't add anchors to other people's pages, you can take advantage of the ones that they have already created. View the source code of their documents to see which anchor names correspond to which sections. (For help viewing source code, consult The Inspiration of Others on page 53.)

  • If the anchor is at the bottom of the page, it may not display at the top of the window, but rather towards the middle.

Previous Page
Next Page

JavaScript EditorBest javascript editor debugger     Ajax website