The number of <a> elements in a document:
let num = document.anchors.length;
Try it Yourself »
The content of the first <a> element:
let content = document.anchors[0].innerHTML;
Try it Yourself »
The anchors property is deprecated. Do NOT use it.
The anchors property only returns those <a> elements with a name attribute.
The name attribute of the <a> element is not supported in HTML5.
The number of <a> elements in a document:
let num = document.getElementsByTagName("a").length;
Try it Yourself »
The content of the first <a> element:
let content = document.getElementsByTagName("a")[0].innerHTML;
Try it Yourself »
document.anchors
NONE |
Type | Description |
Object | An HTMLCollection of all lt;a> elements in the document that have a name attribute. |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!