0% found this document useful (0 votes)
110 views

Anchor Objects

The anchor object is a built-in array that contains an element for every anchor in the current web page. The syntax to access a specific anchor is document.anchor[n] where n is the position of the anchor in the list. Alternatively, document.anchor.length can be used to get the total number of anchors. When the page loads, the anchors array is populated with an element for each anchor, starting with anchor[0] for the first anchor. However, the actual anchor names cannot be accessed through the anchors array.

Uploaded by

api-3772730
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
110 views

Anchor Objects

The anchor object is a built-in array that contains an element for every anchor in the current web page. The syntax to access a specific anchor is document.anchor[n] where n is the position of the anchor in the list. Alternatively, document.anchor.length can be used to get the total number of anchors. When the page loads, the anchors array is populated with an element for each anchor, starting with anchor[0] for the first anchor. However, the actual anchor names cannot be accessed through the anchors array.

Uploaded by

api-3772730
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

anchor Objects (anchors array)

An anchor object is a built-in array that contains one


element for every anchor in the current Web page.

Syntax

The syntax for the anchor object is

document.anchor[n]

where n is some number representing an item's position in


the list. Alternatively, you can use

document.anchor.length

to identify the number of items in the list.


Properties

.length Identifies how many items are in the


anchors array.

Description
When your page is displayed to a reader, the anchors array
creates an element for each anchor in the page. The first
anchor is anchor[0], the next is anchor[1], and so forth.
The anchors.length value reflects the number of items in
the array.
The actual name of the anchor is always null. That is, you
cannot use the anchors array to discover an anchor's
name. You also cannot create an anchor programatically.
For example, the statement anchor[0]="hello" does
nothing.
The anchor object is a property of the larger document
object.
Example
The custom function in the following listing returns true if
the current page has at least one anchor in it. It returns
false if the page contains no anchors.

function hasAnchors() {
retval = true
if (document.anchors.length == 0) {
retval = false
} return retval
}

You might also like