This function finds and returns all DOM elements that matche the given CSS selecotr as a NodeList
. Where no matches are found, an empty NodeList
is returned.
This works like Document.querySelectorAll()
/ Element.querySelectorAll()
but internally polyfills the CSS :is()
, (:matches()
, :any()
) pseudo-class function.
import selectAll from '@web-native-js/play-ui/src/dom/selectAll.js';
selectAll(selector[, context = null]);
selector
-String
: A valid CSS selector.context
-HTMLElement
: An optional node under which to run the query. This would be equivalent tocontext.querySelectorAll(selector)
.
NodeList
- A non-liveNodeList
containing zero or more matched elements.
The example below demonstrates this function with the CSS :is()
pseudo-class function.
<body>
<header>
<div>DIV1</div>
</header>
<main>
<div>DIV2</div>
</main>
</body>
let divs = selectAll(':is(header, main) > div');
console.log(divs.length); // 2