Section 25.1. Anchor: the target of a hypertext link


25.1. Anchor: the target of a hypertext link

DOM Level 0: Node Element HTMLElement Anchor

25.1.1. Properties


Stringname

Contains the name of an Anchor object. The value of this property is set by the name attribute of the <a> tag.

25.1.2. Methods


focus( )

Scrolls the document so the location of the anchor is visible.

25.1.3. HTML Syntax

An Anchor object is created by any standard HTML <a> tag that contains a name attribute:

 <a name="name">  // Links may refer to this anchor by this name     ... </a> 

25.1.4. Description

An anchor is a named location within an HTML document. Anchors are created with an <a> tag that has a name attribute specified. The Document object has an anchors[] array property that contains Anchor objects that represent each of the anchors in the document. Anchor objects can be referenced by index or by name within this array.

You can make a browser display the location of an anchor by setting the hash property of the Location object to a # character followed by the name of the anchor or by simply calling the focus( ) method of the Anchor object itself.

Note that the <a> tag used to create anchors is also used to create hypertext links. Although hypertext links are often called anchors in HTML parlance, they are represented in JavaScript with the Link object, not with the Anchor object.

25.1.5. Example

 // Scroll the document so the anchor named "_bottom_" is visible document.anchors['_bottom_'].focus( ); 

25.1.6. See Also

Document, Link, Location




JavaScript. The Definitive Guide
JavaScript: The Definitive Guide
ISBN: 0596101996
EAN: 2147483647
Year: 2004
Pages: 767

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net