get-elements-array
Array of elements from selector, Array-like objects and single elements.
The purpose of this module is to simplify the interpretation of an "elements" parameter in your own functions/modules, kinda like jQuery does.
Usage
getElements()
always returns a plain Array of elements with many types of input:
// a selector string:elementsArray = ;// => [<img>, <img>, <img>]
// a single DOM element:elementsArray = ;// => [document.body]
// a collection of elements:elementsArray = ;// => [<h1>, <p>, ...]
// an array of elements:elementsArray = ;// => [document.body, document.head]
// an empty collection or null parameter:elementsArray = ;// => []
// `document` or `window:elementsArray = ;// => [document]
Note: it does not verify that the resulting array contains only elements. If needed, you can use a filter on the now-easy-to-use array:
const getElements = ;const isElement = ; const elements = ;// => [document.body]
Install
Pick your favorite:
npm install --save get-elements-array
var getElements = ;
;
Dependencies
None!
Related
- on-off: Add and remove multiple events on multiple elements in <1KB
License
MIT © Federico Brigante