25.195. Link: a hyperlink or anchor in an HTML documentDOM Level 0: Node Element HTMLElement Link25.195.1. PropertiesThe most important property of a Link is its href, which is the URL to which it links. The Link object also defines a number of other properties that hold portions of the URL. For each of these properties, the example given is a portion of the following (fictitious) URL: http://www.oreilly.com:1234/catalog/search.html?q=JavaScript&m=10#results
In addition to these URL-related properties, Link objects also define properties that correspond to the attributes for the HTML <a> and <area> tags:
25.195.2. Methods
25.195.3. Event HandlersThe Link object has special behavior for three event handlers:
25.195.4. HTML SyntaxA Link object is created with standard <a> and </a> tags. The href attribute is required for all Link objects. If the name attribute is also specified, an Anchor object is also created: <a href="url" // The destination of the link [ name="anchor_tag" ] // Creates an Anchor object [ target="window_name" ] // Where the new document should be displayed [ onclick="handler" ] // Invoked when link is clicked [ onmouseover="handler" ] // Invoked when mouse is over link [ onmouseout="handler" ] // Invoked when mouse leaves link >link text or image // The visible part of the link </a> 25.195.5. DescriptionA Link object represents a hyperlink in a document. Links are usually created with <a> tags that have an href attribute defined, but they may also be created with <area> tags inside a client-side image map. When an <a> tag has a name attribute instead of an href attribute, it defines a named position in a document and is represented by an Anchor object instead of a Link object. See Anchor for details. All links in a document (whether created with <a> or <area> tags) are represented by Link objects in the links[] array of the Document object. The destination of a hypertext link is a URL, of course, and many of the properties of the Link object specify the contents of that URL. In this way, the Link object is similar to the Location object, which also has a full set of URL properties. 25.195.6. Example// Get the URL of the first hyperlink in the document var url = document.links[0].href; 25.195.7. See AlsoAnchor, Location |