DOMRectList: item() メソッド
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2020年1月.
DOMRectList
の item()
メソッドは、リスト内の指定されたインデックスの DOMRect
を返します。インデックスが範囲外の場合は null
を返します。
構文
js
item(index)
引数
index
-
取得する
DOMRectList
内のDOMRect
の位置を表す 0 から始まる整数。
返値
DOMRectList
内の指定した位置にある DOMRect
オブジェクト、またはインデックスがリスト内の長方形の数以上である場合は null。
例
js
const rects = document.getElementById("rects").getClientRects();
console.log(rects.length); // DOMRectList の中の長方形の数
if (rects.length > 0) {
console.log(rects.item(0)); // 最初の DOMRect オブジェクトをログ出力
}
仕様書
Specification |
---|
Geometry Interfaces Module Level 1> # dom-domrectlist-item> |
ブラウザーの互換性
Loading…