Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/francoischalifour/selectors-to-array

Converts CSS selectors, DOM elements and NodeLists into arrays
https://github.com/francoischalifour/selectors-to-array

array css-selector dom-element javascript nodelist selector

Last synced: about 1 month ago
JSON representation

Converts CSS selectors, DOM elements and NodeLists into arrays

Awesome Lists containing this project

README

        

# selectors-to-array

> Converts [CSS selectors](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors), [DOM elements](https://developer.mozilla.org/en-US/docs/Web/HTML/Element) and [NodeLists](https://developer.mozilla.org/en-US/docs/Web/API/NodeList) into arrays

## Install

```console
$ npm install --save selectors-to-array
```

## Usage

```js
const selectorsToArray = require('selectors-to-array')

selectorsToArray('input, button')
// => [input#player-1, input#player-2, button]

selectorsToArray(document.querySelector('input'))
// => [input#player-1]

selectorsToArray(document.querySelectorAll('input'))
// => [input#player-1, input#player-2]

const elements = [
document.querySelector('#player-1'),
...document.querySelectorAll('button')
]
selectorsToArray(elements)
// => [input#player-1, button]
```

## License

MIT © [François Chalifour](http://francoischalifour.com)