select-dom
Lightweight querySelector
/All
wrapper that outputs an Array
Install
$ npm install select-dom
Examples
var select = require('select-dom')
select()
select('.foo a[href=bar]')
select('.foo a[href=bar]', baseElement)
select.exists()
select.exists('.foo a[href=bar]')
select.exists('.foo a[href=bar]', baseElement)
select.all()
select.all('.foo a[href=bar]')
select.all('.foo a[href=bar]', baseElement)
select.all('.foo a[href=bar]', [baseElement1, baseElement2])
API
Note: if a falsy value is passed as baseElement
, you'll always get an empty result (bd578b9)
select(selector[, baseElement = document])
Maps to baseElement.querySelector(selector)
select.exists(selector[, baseElement = document])
Tests the existence of one or more elements matching the selector.
select.all(selector[, baseElements = document])
Maps to baseElements.querySelectorAll(selector)
plus:
- it always returns an array
- baseElements can be an element, an array of elements, or NodeList
This lets you search through an existing list of elements, like:
const baseElements = select.all('.baseElements').filter(Math.random);
select.all('.foo a[href=bar]', baseElements);