select-dom
Lightweight querySelector
/All
wrapper that outputs an Array
Install
$ npm install select-dom
Examples
var select = require('select-dom')
select('.foo a[href=bar]')
select('.foo a[href=bar]', parentElement)
select.exists('.foo a[href=bar]')
select.exists('.foo a[href=bar]', parentElement)
select.all('.foo a[href=bar]')
select.all('.foo a[href=bar]', parentElement)
select.all('.foo a[href=bar]', [parentElement1, parentElement2])
API
select(selector[, parent = document])
Maps to parent.querySelector(selector)
select.exists(selector[, parent = document])
Tests the existence of one or more elements matching the selector.
select.all(selector[, parents = document])
Maps to parents.querySelectorAll(selector)
plus:
- it always returns an array
- parents can be undefined, an element, an array of elements, or NodeList
Essentially now you can do something like:
const parents = select.all('.parents');
if(checkSomething(parents)) {
select.all('.foo a[href=bar]', parents);
}