From 7314293c5c2309e78647ed4df02ca6654adb6d36 Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Mon, 18 Oct 2021 23:47:43 +0900 Subject: Web/API/Document/anchors の変換準備 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- files/ja/web/api/document/anchors/index.html | 115 --------------------------- files/ja/web/api/document/anchors/index.md | 115 +++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 115 deletions(-) delete mode 100644 files/ja/web/api/document/anchors/index.html create mode 100644 files/ja/web/api/document/anchors/index.md (limited to 'files') diff --git a/files/ja/web/api/document/anchors/index.html b/files/ja/web/api/document/anchors/index.html deleted file mode 100644 index 3add544412..0000000000 --- a/files/ja/web/api/document/anchors/index.html +++ /dev/null @@ -1,115 +0,0 @@ ---- -title: Document.anchors -slug: Web/API/Document/anchors -tags: - - API - - DOM - - Deprecated - - Document - - HTML DOM - - Property - - Reference - - anchors - - プロパティ -translation_of: Web/API/Document/anchors ---- -
{{APIRef("DOM")}} {{deprecated_header()}}
- -

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

- -

構文

- -
nodeList = document.anchors;
-
- -

- -

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

- -

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

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

- -
<!DOCTYPE html>
-<html lang="en">
-<head>
-<meta charset="UTF-8" />
-<title>Test</title>
-<script>
-function init() {
-  var toc = document.getElementById("toc");
-  var i, li, newAnchor;
-  for (i = 0; i < document.anchors.length; i++) {
-    li = document.createElement("li");
-    newAnchor = document.createElement('a');
-    newAnchor.href = "#" + document.anchors[i].name;
-    newAnchor.innerHTML = document.anchors[i].text;
-    li.appendChild(newAnchor);
-    toc.appendChild(li);
-  }
-}
-</script>
-</head>
-<body onload="init()">
-
-<h1>Title</h1>
-<h2><a name="contents">Contents</a></h2>
-<ul id="toc"></ul>
-
-<h2><a name="plants">Plants</a></h2>
-<ol>
-  <li>Apples</li>
-  <li>Oranges</li>
-  <li>Pears</li>
-</ol>
-
-<h2><a name="veggies">Veggies</a></h2>
-<ol>
-  <li>Carrots</li>
-  <li>Celery</li>
-  <li>Beats</li>
-</ol>
-
-</body>
-</html>
-
- -

JSFiddle で確認

- -

メモ

- -

後方互換性のため、返されるアンカーのセットには name 属性を付けて作成されたアンカーのみが含まれ、 id 属性付きで作成されたものは含まれません。

- -

仕様書

- - - - - - - - - - - - - - - - - - - - - -
仕様書状態備考
{{SpecName('HTML WHATWG', '#dom-document-anchors', 'Document.anchors')}}{{ Spec2('HTML WHATWG') }}廃止
{{SpecName('DOM2 HTML', 'html.html#ID-7577272', 'Document.anchors')}}{{ Spec2('DOM2 Events') }}初回定義
- -

ブラウザーの対応

- -
{{Compat("api.Document.anchors")}}
diff --git a/files/ja/web/api/document/anchors/index.md b/files/ja/web/api/document/anchors/index.md new file mode 100644 index 0000000000..3add544412 --- /dev/null +++ b/files/ja/web/api/document/anchors/index.md @@ -0,0 +1,115 @@ +--- +title: Document.anchors +slug: Web/API/Document/anchors +tags: + - API + - DOM + - Deprecated + - Document + - HTML DOM + - Property + - Reference + - anchors + - プロパティ +translation_of: Web/API/Document/anchors +--- +
{{APIRef("DOM")}} {{deprecated_header()}}
+ +

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

+ +

構文

+ +
nodeList = document.anchors;
+
+ +

+ +

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

+ +

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

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

+ +
<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="UTF-8" />
+<title>Test</title>
+<script>
+function init() {
+  var toc = document.getElementById("toc");
+  var i, li, newAnchor;
+  for (i = 0; i < document.anchors.length; i++) {
+    li = document.createElement("li");
+    newAnchor = document.createElement('a');
+    newAnchor.href = "#" + document.anchors[i].name;
+    newAnchor.innerHTML = document.anchors[i].text;
+    li.appendChild(newAnchor);
+    toc.appendChild(li);
+  }
+}
+</script>
+</head>
+<body onload="init()">
+
+<h1>Title</h1>
+<h2><a name="contents">Contents</a></h2>
+<ul id="toc"></ul>
+
+<h2><a name="plants">Plants</a></h2>
+<ol>
+  <li>Apples</li>
+  <li>Oranges</li>
+  <li>Pears</li>
+</ol>
+
+<h2><a name="veggies">Veggies</a></h2>
+<ol>
+  <li>Carrots</li>
+  <li>Celery</li>
+  <li>Beats</li>
+</ol>
+
+</body>
+</html>
+
+ +

JSFiddle で確認

+ +

メモ

+ +

後方互換性のため、返されるアンカーのセットには name 属性を付けて作成されたアンカーのみが含まれ、 id 属性付きで作成されたものは含まれません。

+ +

仕様書

+ + + + + + + + + + + + + + + + + + + + + +
仕様書状態備考
{{SpecName('HTML WHATWG', '#dom-document-anchors', 'Document.anchors')}}{{ Spec2('HTML WHATWG') }}廃止
{{SpecName('DOM2 HTML', 'html.html#ID-7577272', 'Document.anchors')}}{{ Spec2('DOM2 Events') }}初回定義
+ +

ブラウザーの対応

+ +
{{Compat("api.Document.anchors")}}
-- cgit v1.2.3-54-g00ecf