Package Exports
- get-elements-array
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (get-elements-array) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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 = getElements('.article img');
// => [<img>, <img>, <img>]
// a single DOM element:
elementsArray = getElements(document.body);
// => [document.body]
// a collection of elements:
elementsArray = getElements(document.body.children);
// => [<h1>, <p>, ...]
// an array of elements:
elementsArray = getElements([document.body, document.head]);
// => [document.body, document.head]
// an empty collection or null parameter:
elementsArray = getElements(undefined);
// => []
// `document` or `window:
elementsArray = getElements(document);
// => [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 = require('get-elements-array');
const isElement = require('lodash.iselement');
const elements = getElements([1, document.body]).filter(isElement);
// => [document.body]
Install
Pick your favorite:
<script src="dist/get-elements-array.browser.js"></script>
npm install --save get-elements-array
var getElements = require('get-elements-array');
import getElements from 'get-elements-array';
Dependencies
None!
Related
- on-off: Add and remove multiple events on multiple elements in <1KB
License
MIT © Federico Brigante