Javascript examples for DOM:Document anchors
The anchors collection returns a collection of all <a> elements with name attribute.
Property | Description |
---|---|
length | Returns the number of <a> elements in the collection. |
Method | Description |
---|---|
[index] | <a> element with the specified index (starts at 0). |
item(index) | <a> element with the specified index (starts at 0). |
namedItem(id) | <a> element with the specified id. |
An HTMLCollection Object, representing all <a> elements in the document that have a name attribute.
The elements in the collection are sorted as they appear in the source code
The following code shows how to Find out how many <a> elements there are in the document:
<!DOCTYPE html> <html> <body> <a name="html">HTML Tutorial</a><br> <a name="css">CSS Tutorial</a><br> <a name="xml">XML Tutorial</a><br> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/*from w ww . ja va 2 s . c om*/ var x = document.anchors[0].innerHTML; document.getElementById("demo").innerHTML = x; } </script> </body> </html>