DHTML: DocumentFragment.querySelector メソッド  編集:2021.12.05 by T.A.

指定されたセレクターのグループに一致する DocumentFragment 内の最初の要素を返します。→MS(en)

一致するものが見つからない場合はnullを返します(ドキュメントのノードの深さ優先のプレオーダー・トラバーサルを使用)。

セレクターが ID と一致し、この ID がドキュメント内で誤って数回使用された場合、セレクターは最初に一致した要素を返します。

パラメーターで指定されたセレクターが無効な場合、SYNTAX_ERR 値を持つ DOMException が発生します。

element = documentfragment.querySelector(selectors);
documentfragment
DocumentFragment
selectors
カンマで区切られた 1 つ以上の CSS セレクターを含む DOMString です。
element
¶Element。
<div id="foo\bar"></div>
<div id="foo:bar"></div>

<script>
document.querySelector('#foo\bar')    // Does not match anything
document.querySelector('#foo\\\\bar') // Match the first div
document.querySelector('#foo:bar')     // Does not match anything
document.querySelector('#foo\\:bar')   // Match the second div
</script>

テスト
HTML:

ここに表示
スクリプト:


スクリプト:



表示内容:
表示内容: