Availability: |
| ||||||
Inherits from: | Element object | ||||||
JavaScript syntax: | - | myAnchor = myAnchorArray[aName] | |||||
- | myAnchor = myAnchorArray[anIndex] | ||||||
- | myAnchor = myDocument.anchors[aName] | ||||||
- | myAnchor = myDocument.anchors[anIndex] | ||||||
- | myAnchor = myDocument.getElementById(anElementID) | ||||||
- | myAnchor = myDocument.getElementsByName(aName)[anIndex] | ||||||
- | myAnchor = myDocument.getElementsByTagName("A")[anIndex] | ||||||
- | myAnchor = myDocument.links[aName] | ||||||
- | myAnchor = myDocument.links[anIndex] | ||||||
IE | myAnchor = myDocument.all.anElementID | ||||||
IE | myAnchor = myDocument.all.tags("A")[anIndex] | ||||||
IE | myAnchor = myDocument.all[aName] | ||||||
IE | myAnchor = myDocument.anchors.item(aName)[anIndex] | ||||||
IE | myAnchor = myDocument.links.item(aName)[anIndex] | ||||||
HTML syntax: | <A> ... </A> | ||||||
Argument list: | aName | An associative array reference to the anchor object. | |||||
aName | The name property of the anchor object | ||||||
anIndex | An index into the anchors collection | ||||||
someText | The text (or innerText) property of the anchor | ||||||
anElementID | The ID value of an Element object | ||||||
Object properties: | accessKey, charset, coords, dataFld, dataSrc, hash, host, hostname, href, hreflang, Methods, mimeType, name, nameProp, pathname, port, protocol, protocolLong, recordNumber, rel, rev, search, shape, tabIndex, target, text, type, urn, x, y | ||||||
Object methods: | blur(), focus() | ||||||
Event handlers: | onClick, onMouseDown, onMouseOut, onMouseOver, onMouseUp |
This object represents a named location in the HTML document. Only those <A> HTML tags that have a NAME attribute will have anchor objects created for them. All the anchors are listed in the anchors[] array object that belongs to the document object that represents the HTML.
Although the <A> tag is also used to create links using the HREF attribute, they are not anchors unless they are named. Any <A> tags that have HREF attributes (whether or not they have NAME attributes) will be listed in the links[] array.
In Netscape, you can construct new instances of the Anchor object, but there is no constructor property in MSIE to support this.
<A> tags and the objects that represent them are inline elements. Placing them into a document does not create a line break.
If you put an anchor object into a document.write(), in Netscape you get a string containing the object class. In MSIE, you will get the HREF string if there is one and an empty string if there isn't.
MSIE provides access to properties that would normally be considered part of the link object. Internally MSIE probably maintains a single object type for anchors and links, whereas Netscape implements two quite different classes.
Netscape supports an associative reference to an anchor object within the anchors[] array according to the value of its NAME tag attribute. MSIE does not support this means of locating an anchor object in quite the same way.
Note that although the syntax examples illustrate the use of an innerText property, Netscape does not support this mode of access and it will generate an error.
<!-- Example showing how to dynamically replace --> <!-- the anchor text --> <HTML> <HEAD> </HEAD> <BODY> <A NAME="A1" HREF="www.apple.com">Click here</A><BR> <A NAME="A2" HREF="www.wrox.com">Click here</A><BR> <A NAME="A3" HREF="www.msdn.com">Click here</A><BR> <BR> <HR> <SCRIPT> myLength = document.anchors.length; for (myEnumerator=0; myEnumerator<myLength; myEnumerator++ ) { document.anchors[myEnumerator].innerText = document.anchors[myEnumerator].name; } </SCRIPT> </BODY> </HTML>
Property | JavaScript | JScript | N | IE | Opera | NES | ECMA | DOM | CSS | HTML | Notes |
---|---|---|---|---|---|---|---|---|---|---|---|
accessKey | 1.5 ![]() | 3.0 ![]() | 6.0 ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | 1 ![]() | ![]() | ![]() | ![]() |
charset | 1.5 ![]() | 5.0 ![]() | 6.0 ![]() | 5.0 ![]() | ![]() | ![]() | ![]() | 1 ![]() | ![]() | ![]() | - |
coords | 1.5 ![]() | 5.0 ![]() | 6.0 ![]() | 5.0 ![]() | ![]() | ![]() | ![]() | 1 ![]() | ![]() | ![]() | - |
dataFld | ![]() | 3.0 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | - |
dataSrc | ![]() | 3.0 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | - |
hash | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
host | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
hostname | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
href | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | 1 ![]() | ![]() | ![]() | ![]() |
hreflang | 1.5 ![]() | 5.0 ![]() | 6.0 ![]() | 5.0 ![]() | ![]() | ![]() | ![]() | 1 ![]() | ![]() | ![]() | - |
Methods | ![]() | 3.0 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | - |
mimeType | ![]() | 3.0 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
name | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | 1 ![]() | ![]() | ![]() | ![]() |
nameProp | ![]() | 3.0 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ReadOnly |
pathname | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
port | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
protocol | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
protocolLong | ![]() | 3.0 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ReadOnly |
recordNumber | ![]() | 3.0 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ReadOnly |
rel | 1.5 ![]() | 3.0 ![]() | 6.0 ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | 1 ![]() | ![]() | ![]() | - |
rev | 1.5 ![]() | 3.0 ![]() | 6.0 ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | 1 ![]() | ![]() | ![]() | - |
search | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
shape | 1.5 ![]() | 5.0 ![]() | 6.0 ![]() | 5.0 ![]() | ![]() | ![]() | ![]() | 1 ![]() | ![]() | ![]() | - |
tabIndex | 1.5 ![]() | 3.0 ![]() | 6.0 ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | 1 ![]() | ![]() | ![]() | - |
target | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | 1 ![]() | ![]() | ![]() | ![]() |
text | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
type | 1.5 ![]() | 3.0 ![]() | 6.0 ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | 1 ![]() | ![]() | ![]() | - |
urn | ![]() | 3.0 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | - |
x | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
y | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
Method | JavaScript | JScript | N | IE | Opera | NES | ECMA | DOM | CSS | HTML | Notes |
---|---|---|---|---|---|---|---|---|---|---|---|
blur() | 1.5 ![]() | 3.0 ![]() | 6.0 ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | 1 ![]() | ![]() | ![]() | - |
focus() | 1.5 ![]() | 3.0 ![]() | 6.0 ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | 1 ![]() | ![]() | ![]() | - |
Event name | JavaScript | JScript | N | IE | Opera | NES | ECMA | DOM | CSS | HTML | Notes |
---|---|---|---|---|---|---|---|---|---|---|---|
onClick | 1.2![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | 4.0 ![]() | ![]() |
onMouseDown | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | 4.0 ![]() | ![]() |
onMouseOut | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | 4.0 ![]() | ![]() |
onMouseOver | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | 4.0 ![]() | ![]() |
onMouseUp | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | 4.0 ![]() | ![]() |
Prev | Home | Next |
AlphaImageLoader() | Up | Anchor() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |