Lightweight
querySelector
/All
wrapper that outputs an Array
Version 5+ only supports browsers with Set
support. If you need IE 10- support, stick to select-dom@4
$ npm install select-dom
const select = require('select-dom')
select('.foo a[href=bar]')
// => <Element>
select('.foo a[href=bar]', baseElement)
// => <Element>
select.exists('.foo a[href=bar]')
// => true/false
select.exists('.foo a[href=bar]', baseElement)
// => true/false
select.all('.foo a[href=bar]')
// => [<Element>, <Element>, <Element>]
select.all('.foo a[href=bar]', baseElement)
// => [<Element>, <Element>, <Element>]
select.all('.foo a[href=bar]', [baseElement1, baseElement2])
// => [<Element>, <Element>, <Element>]
Note: if a falsy value is passed as baseElement
, you'll always get an empty result (bd578b9)
Maps to baseElement.querySelector(selector)
Tests the existence of one or more elements matching the selector.
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);
- delegate-it - DOM event delegation, in <1KB.
- doma - Parse an HTML string into
DocumentFragment
or oneElement
, in a few bytes. - Refined GitHub - Uses this module.