Search Index
Search Index

A

The "A" element lets you define anchors and links. An anchor defines a place in a document. A link displays a hypertext link that the user can click to display an anchor or a new document.

HTML Syntax

The "A" element requires either an id or a name attribute. All other attributes are optional. An end tag is required. "A" elements may not be nested inside other "A" elements.

<A

id = ID
class = text (CDATA)
style = Style Sheet
title = text
lang = Language Code
dir = Text Direction
target = Target
charset = Charset
type = Content Type
name = Text (CDATA)
href = URL
hreflang = Language Code
rel = Link Type
rev = Link Type
accessKey = Character
tabIndex = Number
onclick = Script
ondblclick = Script
onmousedown = Script
onmouseup = Script
onmousemove = Script
onmouseout = Script
onkeypress = Script
onkeydown = Script
onkeyup = Script
onfocus = Script
onblur = Script
>

Document Object Model Syntax

Attributes of the "A" element are exposed in JavaScript as properties on the element object. The name of the exposed property always uses the DOM naming conventions, and is independent of the case of the attribute in the source document.

Properties

target, charset, type, name, href, hreflang, rel, rev, accessKey, tabIndex,

Methods

getAttribute(), setAttribute(), removeAttribute(), getAttributeNode(), setAttributeNode(), removeAttributeNode(), getElementsByTagName(), normalize(), blur(), focus()

Detailed Attribute Descriptions

This lists details the "A" element's attributes.

Note that HTML element attributes are exposed in JavaScript as properties on the element object. Unlike HTML, JavaScript is case sensitive. These attribute names are shown using case that will work in either HTML or JavaScript. Note that a small number of HTML attribute names may have a different name when used as a property in JavaScript.

id
This attribute assigns a name to an element. This name must be unique in a document.
class
This attribute assigns a class name or set of class names to an element. Any number of elements may be assigned the same class name or names. Multiple class names must be separated by white space characters. When accessed from JavaScript, this property is called "className."
style
This attribute specifies style information for the current element.
title
This attribute offers advisory information about the element for which it is set.
lang
This attribute specifies the base language of an element's attribute values and text content. The default value of this attribute is unknown.
dir
This attribute specifies the base directionality of text and the directionality of tables. Possible values:
target
This attribute specifies a window in which to show the destination document (if the link's action is to scroll or open a document). If the named window is not already open, a new window with that name opens. Special target values include: "_blank" opens the destination document in a new unnamed window. "_parent" opens the destination document in the parent window of the one displaying the current document. "_self" opens the destination document in the same window as the one in which the link was clicked. "_top" opens the destination document in the full body of the current window. This value can be used to ensure that the destination document takes over the full window even if the original document was displayed in a frame.
charset
This attribute specifies the character encoding of the resource designated by the link.
type
This attribute specifies the content type of a piece of content that is being linked.
name
This attribute names the current anchor so that it may be the destination of another link. The value of this attribute must be a unique anchor name. The scope of this name is the current document. Note that this attribute shares the same name space as the id attribute.
href
This attribute specifies the location of a Web resource, thus defining a link between the current element (the source anchor) and the destination anchor defined by this attribute.
hreflang
This attribute specifies the base language of the resource designated by href and may only be used when href is specified
rel
This attribute describes the relationship from the current document to the anchor specified by the href attribute. The value of this attribute is a space-separated list of link types.
rev
This attribute is used to describe a reverse link from the anchor specified by the href attribute to the current document. The value of this attribute is a space-separated list of link types.
accessKey
This attribute assigns an access key to an element. An access key is a single character from the document character set. Pressing an access key assigned to an element gives focus to the element and activates it. When a user activates a link defined by the A element, NGLayout follows the link. The invocation of access keys depends on the underlying system. For instance, on machines running MS Windows, one generally has to press the "alt" key in addition to the access key. On Apple systems, one generally has to press the "cmd" key in addition to the access key. NGLayout will underline the value of an access key in such a way as to emphasize its role and to distinguish it from other characters.
tabIndex
This attribute specifies the position of the current element in the tabbing order for the current document. This value must be a number between 0 and 32767. The tabbing order defines the order in which elements will receive focus when navigated by the user via the keyboard (normally via the "tab" key). The tabbing order may include elements nested within other elements. Elements that may receive focus are navigated by NGLayout according to the following rules: Those elements that support the tabindex attribute and assign a positive value to it are navigated first. Navigation proceeds from the element with the lowest tabindex value to the element with the highest value. Values need not be sequential nor must they begin with any particular value. Elements that have identical tabindex values should be navigated in the order they appear in the document source. Those elements that do not support the tabindex attribute or support it and assign it a value of "0" are navigated next. These elements are navigated in the order they appear in the document source. Elements that are disabled do not participate in the tabbing order.
onclick
This attribute is used to associate JavaScript with the "onclick" event. The onclick event occurs when a mouse button is clicked over the element.
ondblclick
This attribute is used to associate JavaScript with the "ondblclick" event. The ondblclick event occurs when a mouse button is double clicked over the element.
onmousedown
This attribute is used to associate JavaScript with the "onmousedown" event. The onmousedown event occurs when a mouse button is pressed over the element.
onmouseup
This attribute is used to associate JavaScript with the "onmouseup" event. The onmouseup event occurs when a mouse button is released over the element.
onmouseover
This attribute is used to associate JavaScript with the "onmouseover" event. The onmouseover event occurs when the mouse is moved onto the element.
onmouseout
This attribute is used to associate JavaScript with the "onmouseout" event. The onmouseout event occurs when the mouse is moved away from the element.
onkeypress
This attribute is used to associate JavaScript with the "onkeypress" event. The onkeypress event occurs when a key is pressed and released over the element.
onkeydown
This attribute is used to associate JavaScript with the "onkeydown" event. The onkeydown event occurs when a key is pressed down over the element.
onkeyup
This attribute is used to associate JavaScript with the "onkeyup" event. The onkeyup event occurs when a key is released over the element.
onfocus
This attribute is used to associate JavaScript with the "onfocus" event. The onfocus event occurs when the element receives focus either by the mouse or by tabbing navigation.
onblur
This attribute is used to associate JavaScript with the "onblur" event. The onblur event occurs when the element loses focus either by the mouse or by tabbing navigation.

Related Resources

HTML 4.0 Recommendation, Section 12.2: The "A" element
DOM Level 1 HTML Recommendation: the HTMLAnchorElement interface
Netscape Navigator 4.0 documentation for the "A" element
Microsoft Internet Explorer 5.0 documentation for the "A" element