dumb-query-selector

Shortcuts to the querySelector(All) functions, the (All) instead returning an array of nodes (because NodeLists are dumb)

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
dumb-query-selector
3.3.06 years ago7 years agoMinified + gzip package size for dumb-query-selector in KB

Readme

Dumb Query Selector
Build Status Coverage Status GitHub Release License
Shortcuts to the querySelector(All) functions, the (All) instead returning an array of nodes (because NodeLists 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 to `document` if
not specified.