An array containing an entry for each link in a document. The array stores an entry for each area and link object in a document; these entries are in source order. For example, if a document contains three links link-1, link-2, link-3 you can refer them as:
You can refer to the Area and Link objects in your code by using the links array. This array contains an entry for each Area (<area href = "..."> tag) and Link (<a href = "..."> tag) object in a document in source order. It also contains links created with the link method. For example, if a document contains three links, you can refer to them as:
In the same spirit as the anchors property, you have the links property. Most pages contain several link definitions throughout the html code, as created by the <a href => tag. document.links is another object array that contains each of the links specified in the current page. Similar to document.anchors, for as many links as there are in the page, there are properties of document.links, in the following manner:
To get the number of links in a document, use the length property : document.links.length.
Where link1, link2,.....,linkN represent the name of the links in the document.
Where 0,1, ...n represent index count.
Example of Document object : links property
In the following web document, the links array is used to get the source of each link.
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<h3>See the source of the each link object.</h3>
document.write("The link object's URL is ",document.links[i].href,"</b><br />")
|Internet Explorer 7||Firefox 3.6||Google Chrome 7||Safari 5.0.1||Opera 10|
See also :
Please Google+, Like this tutorial on FaceBook, Tweet, save it as bookmark and subscribe with our Feed. Have suggestions? comment using Disqus down this page. Thanks.