HTML | DOM anchors Collection
The DOM anchors collection is used to return the collection of all <a> element in a HTML document. It only counts those <a> element that has the name attribute only. The name attribute of anchor element does not support in HTML 5. The elements in the collection are sorted that appear in the sourcecode.
Note: DOM anchor collection has been deprecated.
Property: The anchor collection property contains a value length which returns the number of <a> elements in the document.
Methods: The DOM anchors collection contains three methods which are given below:
- [index]: It is used to return the <a> element of selected index. The index value starts with 0. It returns NULL if the index value is out of range.
- item(index): It is used to return the <a> element of selected index. The index value starts with 0. It returns NULL if the index value is out of range.
- namedItem(id): It is used to return the <a> element from the collection with given id attribute. It returns NULL if the id is not valid.
Return Value: 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
Supported Browsers: The browser supported by DOM anchors collection are listed below:
- Google Chrome
- Internet Explorer