Name
Anchor: the target of a hypertext link — DOM Level 0: Node → Element → HTMLElement → Anchor
Properties
-
Stringname Contains the name of an Anchor object. The value of this property is set by the
nameattribute of the<a>tag.
Methods
-
focus( ) Scrolls the document so the location of the anchor is visible.
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>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.
Example
// Scroll the document so the anchor named "_bottom_" is visible document.anchors['_bottom_'].focus( );
See Also
Document, Link, Location
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access