From df6bd536b03c31c97e2d9998a4f7e1b56133fcfe Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Mon, 18 Oct 2021 23:52:01 +0900 Subject: Web/API/Document/anchors を更新 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 2021/10/18 時点の英語版に同期 --- files/ja/web/api/document/anchors/index.md | 146 +++++++++++++---------------- 1 file changed, 63 insertions(+), 83 deletions(-) (limited to 'files/ja/web') diff --git a/files/ja/web/api/document/anchors/index.md b/files/ja/web/api/document/anchors/index.md index 3add544412..f102b496df 100644 --- a/files/ja/web/api/document/anchors/index.md +++ b/files/ja/web/api/document/anchors/index.md @@ -3,113 +3,93 @@ title: Document.anchors slug: Web/API/Document/anchors tags: - API - - DOM - Deprecated - Document - HTML DOM - Property - Reference - - anchors - - プロパティ +browser-compat: api.Document.anchors translation_of: Web/API/Document/anchors --- -
{{APIRef("DOM")}} {{deprecated_header()}}
+{{APIRef("DOM")}} {{Deprecated_Header}} -

anchors は {{domxref("Document")}} インターフェイスの読み取り専用のプロパティで、文書中のすべてのアンカーのリストを返します。

+**`anchors`** は {{domxref("Document")}} インターフェイスの読み取り専用のプロパティで、文書中のすべてのアンカーのリストを返します。 -

構文

+## 構文 -
nodeList = document.anchors;
-
+```js +nodeList = document.anchors; +``` -

+### 値 -

{{domxref("HTMLCollection")}} です。

+{{domxref("HTMLCollection")}} です。 -

+## 例 -
if (document.anchors.length >= 5) {
-  dump("dump found too many anchors");
-  window.location = "http://www.google.com";
+```js
+if (document.anchors.length >= 5) {
+  dump("found too many anchors");
 }
-
+``` -

文書中のアンカーを基に目次を作成して文書に挿入する例を以下に示します。

+文書中のアンカーを基に目次を作成して文書に挿入する例を以下に示します。 -
<!DOCTYPE html>
-<html lang="en">
-<head>
-<meta charset="UTF-8" />
-<title>Test</title>
-<script>
+```html
+
+
+
+
+Test
+
+
+
+
+

Title

+

Contents

+ + +

Plants

+
    +
  1. Apples
  2. +
  3. Oranges
  4. +
  5. Pears
  6. +
+ +

Veggies

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