links collection
Browser support:Represents a collection of all anchor and area elements in the current document that have a href property specified.
The elements in the collection are sorted in source code order.
Syntax:
Properties that reference the object:
| | document.links |
The base interface, through which you can add new functionalities to the links collection, is the HTMLCollection interface.
Possible members:
Properties:
|
Returns an integer that specifies the number of elements in the current collection.
This property is read-only. |
Methods:
| [nameOrIndex] |
Returns an element or a collection of elements from the current collection by name or index.
Parameters:
Return value:
In Firefox, if more than one match is found, the first matching element is returned.
|
||||||||||||||||||||||
| item (nameOrIndex [, subIndex]) |
Returns an element or a collection of elements from the current collection by name or index.
Parameters:
Return value:
|
||||||||||||||||||||||
| namedItem (name) |
Returns an element or a collection of elements from the current collection by name.
Parameters:
Return value:
|
||||||||||||||||||||||
| tags | Returns a NodeList collection that contains all elements from the current collection with the specified tag name. | ||||||||||||||||||||||
| urns | Returns a NodeList collection that contains all elements to which the specified behavior is attached. |
Example HTML code 1:
This example illustrates the use of the links collection:
|
|
||||
<head> <script type="text/javascript"> function GetLinks () { message = ""; for (var i = 0; i < document.links.length; i++) { var link = document.links[i]; message += "The href property of the " + i + ". link is '" + link.href + "'.\n"; } alert (message); } </script> </head> <body> <button onclick="GetLinks ();">Get links on the page!</button> <br /><br /> Table of contents: <ul> <li><a href="#section1">1. Section</a></li> <li><a href="#section2">2. Section</a></li> <li><a href="#section3">3. Section</a></li> </ul> <b><a name="section1">1. Section</a></b><br /> First line in the section.<br />...<br />...<br />...<br /> Last line in the section.<br /><br /> <b><a name="section2">2. Section</a></b><br /> First line in the section.<br />...<br />...<br />...<br /> Last line in the section.<br /><br /> <b><a name="section3">3. Section</a></b><br /> First line in the section.<br />...<br />...<br />...<br /> Last line in the section.<br /><br /> </body> |
||||
|
||||
|
Did you find this example helpful?
|
External links:
User Contributed Comments
