HTML DOM anchors collection
HTML DOM anchors Collection
Definition and usage
The anchors collection returns an array of all hyperlinks on the current page.
Syntax
document.anchors[].property
Browser support
All major browsers support anchors collection
Example
Example
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <a name="html">HTML 教程</a><br> <a name="css">CSS 教程</a><br> <a name="xml">XML 教程</a><br> <a href="/js/">JavaScript 教程</a> <p>锚的数量: <script> document.write(document.anchors.length); </script></p> </body> </html>
Run Instance»
Click the "Run Instance" button to view the online instance
Instance
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <a name="html">HTML 教程</a><br> <a name="css">CSS 教程</a><br> <a name="xml">XML 教程</a> <p>文档中第一个锚: <script> document.write(document.anchors[0].innerHTML); </script> </p> </body> </html>
Run instance»
Click the "Run instance" button to view the online instance