Javascript examples for DOM:Document links
The links collection returns all links in the document representing <a> elements and/or <area> elements with a href attribute.
If the element is missing the href attribute, nothing is returned.
Property | Description |
---|---|
length | Returns the number of <a> and/or <area> elements in the collection. |
Method | Description |
---|---|
[index] | <a> and/or <area> element with the specified index (starts at 0). |
item(index) | <a> and/or <area> element with the specified index (starts at 0). |
namedItem(id) | <a> and/or <area> element with the specified id. |
An HTMLCollection Object, representing all <a> elements and/or <area> elements in the document.
The following code shows how to Find out how many links there are in the document:
<!DOCTYPE html> <html> <body> <p> <a href="/html/default.asp">HTML</a><br> <a href="/css/default.asp">CSS</a> </p>//from w w w.j a va2 s . com <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { document.links[0].style.border = "5px solid red"; } </script> </body> </html>