9.0.0 • Published 7 months ago

select-dom v9.0.0

Weekly downloads
1,403
License
MIT
Repository
github
Last release
7 months ago

select-dom npm downloads

Lightweight querySelector/All wrapper that outputs an Array

Version 7+ only supports browsers with iterable NodeLists. If you need IE support, stick to select-dom@6 or lower.

Install

npm install select-dom
// This module is only offered as a ES Module
import {$, $$, lastElement, elementExists} from 'select-dom';

API

Note: if a falsy value is passed as baseElement, you'll always get an empty result (bd578b9)

$(selector[, baseElement = document])

Maps to baseElement.querySelector(selector), except it returns undefined if it's not found

$('.foo a[href=bar]');
// => <Element>

$('.foo a[href=bar]', baseElement);
// => <Element>

$('.non-existent', baseElement);
// => undefined

lastElement(selector[, baseElement = document])

Like $(), except that it returns the last matching item on the page instead of the first one.

elementExists(selector[, baseElement = document])

Tests the existence of one or more elements matching the selector. It's like $(), except it returns a boolean.

elementExists('.foo a[href=bar]');
// => true/false

elementExists('.foo a[href=bar]', baseElement);
// => true/false

$$(selector[, baseElements = document])

Maps to baseElements.querySelectorAll(selector) plus:

  • it always returns an array
  • baseElements can be a list of elements to query
$$('.foo');
// => [<Element>, <Element>, <Element>]

$$('.foo', baseElement);
// => [<Element>, <Element>, <Element>]

$$('.foo', [baseElement1, baseElement2]);
// => [<Element>, <Element>, <Element>]
// This is similar to jQuery([baseElement1, baseElement2]).find('.foo')

Related

  • delegate-it - DOM event delegation, in <1KB.
  • doma - Parse an HTML string into DocumentFragment or one Element, in a few bytes.
9.0.0

7 months ago

8.0.0

10 months ago

7.1.1

3 years ago

7.1.0

3 years ago

7.0.0-6

3 years ago

7.0.0-5

3 years ago

7.0.0-4

3 years ago

7.0.0-3

3 years ago

7.0.0-2

3 years ago

7.0.0-1

3 years ago

7.0.0-0

3 years ago

7.0.0

3 years ago

6.0.2

4 years ago

6.0.1

4 years ago

6.0.0

4 years ago

5.1.0

5 years ago

5.0.2

5 years ago

5.0.1

5 years ago

5.0.0

5 years ago

4.2.2

5 years ago

5.0.0-0

5 years ago

4.2.1

5 years ago

4.2.0

5 years ago

4.2.0-3

5 years ago

4.2.0-2

5 years ago

4.2.0-1

5 years ago

4.2.0-0

5 years ago

4.1.3

6 years ago

4.1.2

6 years ago

4.1.1

7 years ago

4.1.0

7 years ago

4.0.0

7 years ago

3.0.2

8 years ago

3.0.1

8 years ago

3.1.0

8 years ago

1.0.1

8 years ago

0.0.1-security

8 years ago

2.0.0

8 years ago

0.0.0

11 years ago