--- title: Document.anchors slug: Web/API/Document/anchors tags: - API - Deprecated - Document - HTML DOM - Property - Reference browser-compat: api.Document.anchors translation_of: Web/API/Document/anchors --- {{APIRef("DOM")}} {{Deprecated_Header}} **`anchors`** は {{domxref("Document")}} インターフェイスの読み取り専用のプロパティで、文書中のすべてのアンカーのリストを返します。 ## 構文 ```js nodeList = document.anchors; ``` ### 値 {{domxref("HTMLCollection")}} です。 ## 例 ```js if (document.anchors.length >= 5) { dump("found too many anchors"); } ``` 文書中のアンカーを基に目次を作成して文書に挿入する例を以下に示します。 ```html Test

Title

Contents

Plants

  1. Apples
  2. Oranges
  3. Pears

Veggies

  1. Carrots
  2. Celery
  3. Beats
``` [JSFiddle で確認](https://jsfiddle.net/S4yNp) ## メモ 後方互換性のため、返されるアンカーのセットには `name` 属性を付けて作成されたアンカーのみが含まれ、 `id` 属性付きで作成されたものは含まれません。 ## 仕様書 {{Specifications}} ## ブラウザーの互換性 {{Compat}}