Document.links - ハイパーリンク
概要
- 名前
- links
- 所属
- Document
- IDL
[SameObject] readonly attribute HTMLCollection links;
- 仕様書
- https://html.spec.whatwg.org/multipage/dom.html#dom-document-links
説明
全てのa要素、area要素をHTMLCollectionで返す。読み取り専用なので、値を代入して変更することはできない。
チュートリアル
Document.linksを利用して、a要素、area要素を取得する例です。
<a href="https://syncer.jp/">
<area href="https://example.com/">
var links = document.links ;
links[0] ; // <a href="https://syncer.jp/">
links[1] ; // <area href="https://example.com/">
デモ
Document.linksのデモです。
<!-- このコードは編集できます。 -->
<!DOCTYPE html>
<html>
<head>
<base target="_blank">
</head>
<body>
<p><a href="https://syncer.jp/">SYNCER</a></p>
<p><a href="https://example.com/">example.com</a></p>
<hr>
<script>
var value = document.links ;
console.log( value ) ;
document.body.appendChild( new Text( value ) ) ;
</script>
</body>
</html>
サポート状況
Chrome | Firefox | Safari | Edge | IE | Opera | iOS Safari | Android |
---|---|---|---|---|---|---|---|
● | ● | ● | ● | ● | ● | ● | ● |
関連記事
- HTMLCollection
- HTMLCollectionは、HTML要素の集合を表すオブジェクトです。Elementだけが含まれた配列であるかのように、手軽にインデックス番号でアクセスできます。
- Document.visibilityState
- visibilityStateは、Documentのプロパティです。最上位のブラウジングコンテキストが持つドキュメントの表示状態を文字列で返します。
- Document.createNodeIterator()
- createNodeIterator()は、Documentのメソッドです。NodeIteratorを新しく作成します。createNodeIterator()とcreateTreeWalker()は、作成するオブジェクトが違うだけで、仕組みは同じです。
- NonElementParentNode.getElementById()
- getElementById()は、NonElementParentNodeのメソッドです。id属性を指定して要素を取得します。