DocumentFragment: querySelectorAll() メソッド

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

DocumentFragment.querySelectorAll() メソッドは NodeList で、 DocumentFragment の中で指定されたセレクター群に一致する要素の一覧を(文書ノードの深さ優先前順走査 (depth-first pre-order traversal) を使用して)返します。

引数で指定されたセレクターが無効であった場合、 DOMExceptionSYNTAX_ERR の値で発生します。

構文

js
querySelectorAll(selectors)

引数

selectors

文字列で、1 つ以上の CSS セレクターをカンマで区切って指定します。

返値

生きていない NodeList です。これには、指定されたセレクター群の少なくとも 1 つに一致する要素ごとに 1 つの Element オブジェクトが格納されます。一致するものがなかった場合は空の NodeList となります。

この例は、 DocumentFragment の中にあるすべての div 要素のうち、 "note" または "alert" クラスのついたものすべてのリストを返します。

js
const matches = documentfrag.querySelectorAll("div.note, div.alert");

仕様書

Specification
DOM
# ref-for-dom-parentnode-queryselectorall①

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
querySelectorAll

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報