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

Latest commit

 

History

History
51 lines (33 loc) · 1.27 KB

select.md

File metadata and controls

51 lines (33 loc) · 1.27 KB

DOM/select()

This function finds and returns the first DOM element that matches the given CSS selecotr. Where no matches are found, NULL is returned.

This works like Document.querySelector() / Element.querySelector() but internally polyfills the CSS :is(), (:matches(), :any()) pseudo-class function.

Import

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

Syntax

select(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.querySelector(selector).

Return

  • HTMLElement - The matched element.
  • NULL - if no matches were found.

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 div = select(':is(header, main) > div');
console.log(div.innerText); // DIV1