Skip to content
This repository has been archived by the owner on Dec 17, 2021. It is now read-only.

Latest commit

 

History

History
50 lines (32 loc) · 1.32 KB

selectall.md

File metadata and controls

50 lines (32 loc) · 1.32 KB

DOM/selectAll()

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

import selectAll from '@web-native-js/play-ui/src/dom/selectAll.js';

Syntax

selectAll(selector[, context = null]);

Parameters

  • selector - String: A valid CSS selector.
  • context - HTMLElement: An optional node under which to run the query. This would be equivalent to context.querySelectorAll(selector).

Return

  • NodeList - A non-live NodeList containing zero or more matched elements.

Usage

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