Query by attribute.a[name] matches the same legacy targets.
Get a NodeList. Standard DOM API — not the deprecated property.
Read the name.getAttribute("name") (or .name on anchors).
Better long-term. For new navigation, prefer id + href="#id".
Compatibility
Browser Support
Document.anchors is Deprecated (MDN). Engines may still expose it for legacy pages, but new code should not depend on it.
✓ Deprecated · Legacy
Document.anchors
Legacy HTMLCollection of named anchors — prefer querySelectorAll("a[name]") or id fragments.
LegacyAvoid in new apps
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
Android WebViewSupported · Modern WebView
Full support
anchorsDeprecated
Bottom line: Still present in many browsers for old content. For production features, use querySelectorAll("a[name]") or modern id-based in-page links.
Frequently Asked Questions
A read-only HTMLCollection of every anchor element in the document that has a name attribute — legacy in-page targets such as <a name="section">.
Yes. MDN marks Document.anchors as Deprecated. Prefer document.querySelectorAll("a[name]") when you need named anchors, or modern id-based fragment links (#id).
No. For backwards compatibility, the collection only includes anchors created with the name attribute, not those created with id alone.
document.anchors lists named anchors (<a name="...">). document.links lists hyperlinks (<a href="...">). An <a> can appear in both if it has name and href.
Yes. Use for...of, a classic indexed for loop, or Array.from. The collection is live — it updates when matching anchors are added or removed.
No. Prefer querySelectorAll("a[name]") for named anchors, or put id on headings and link with href="#id".