dumb-query-selector
v3.3.0
Published
Shortcuts to the querySelector(All) functions, the (All) instead returning an array of nodes (because NodeLists are dumb)
Downloads
6,945
Readme
Dumb Query Selector
Shortcuts to the querySelector(All)
functions, the (All)
instead returning
an array of nodes (because NodeList
s are dumb).
Installation
Via Bower:
bower install dumb-query-selector --save
Via NPM:
npm install dumb-query-selector --save
Since this project is only 1 script, you can also download the script to your project if you prefer: dumb-query-selector.js.
Usage
This project exports 2 functions via UMD, $
and $$
, and is available to you through a variety of different module loaders.
If used in the browser outside of a module environment, then both functions are
available globally.
The first, $
, returns a single node, whereas $$
returns an array of nodes.
import {$, $$} from 'dumb-query-selector';
// Return matching element, use it directly
let result = $('#some-id');
let blah = result.getAttribute('data-blah');
// Return array of matching elements, allowing the use of array functions
let results = $$('.some-classes');
results.forEach(result => {
// ...
});
Both functions take up to 2 arguments:
query Type:
String
A standard CSS selector.scope Type:
Node
Optional context on which to invoke the function. Defaults todocument
if not specified.