💡
要素取得判定関数まとめ
子要素取得系
| 関数名 | 戻型 | セレクタ | 使えるインスタンス |
|---|---|---|---|
| getElementById | Element | null | ID属性値 | Document , DocumentFragment |
| getElementsByName | 生きた NodeList | Name属性値 | Document |
| getElementsByTagName | 生きた HTMLCollection | タグ名 | Document, Element |
| getElementsByTagNameNS | 生きた NodeList | タグ名 + 名前空間URI | Document, Element |
| getElementsByClassName | 生きた HTMLCollection | classList の要素値 | Document, Element |
| evaluate | XPathResult | XPath | Document, XPathExpression |
| querySelector | Element | null | CSS セレクタ | Document, Element, DocumentFragment |
| querySelectorAll | (生きてない) NodeList | CSS セレクタ | Document, Element, DocumentFragment |
自身から親方向に向けた要素取得系
| 関数名 | 戻型 | セレクタ | 使えるインスタンス |
|---|---|---|---|
| evaluate | XPathResult | XPath | Document, XPathExpression |
| closest | Element | null | CSS セレクタ | Element |
自身判定系
| 関数名 | セレクタ | 使えるインスタンス |
|---|---|---|
| evaluate | XPath | Document, XPathExpression |
| matches | CSS セレクタ | Element |
感想
基本的には getElementById / querySelector / querySelectorAll / closest / matches でこと足りるかな感
evaluate はなんでもできるが IEに実装されなかったことだけが惜しい。
Discussion