.queryAll()
Elements ParentNode.queryAll(String relativeSelectors)
Warning! Current browsers do not yet support
.queryAll(), please
use a polyfill
until they do.
Finds all element matching the supplied relative selectors, returns an Elements collection, which is a sub-class of Array and has all the usual Array methods (eg. filter, map, etc.)
node.queryAll(relativeSelector);Returns all the elements that are descedents of node that match relativeSelectors.
To query the entire document, simply do:
document.queryAll(relativeSelector);See also: .query()
Examples
HTML:
<ul class="list-one">
<li class="one">Item 1</li>
<li>
<ul class="list-two">
<li class="two">Item 2</li>
<li class="three">Item 3</li>
</ul>
</li>
</ul>Example 1
JavaScript:
let result = document.queryAll(".two");Result is an Elements list with one element: <li class="two">Item 2</li>.
Example 2
JavaScript:
let ul = document.query("ul");
let result = ul.query("> *");Result is an Elements list with two elements: <li class="one">Item 1</li> and <li><ul class="list-two">...</ul></li>.