JSPM

get-elements-array

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5
  • Score
    100M100P100Q28338F
  • License MIT

Array of elements from selector, Array-like objects and single elements

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.

gzipped size Travis build status npm version

Similar to how jQuery works and perfect to parse the "elements" parameter of your module.

Usage

getElements() accepts:

  • a selector string like getElements('.article img')
  • a single DOM element, like getElements(document.body)
  • a collection of elements, like getElements(document.body.children)
  • an array of elements, like getElements([document.body, document.head])
  • an empty collection or null parameter, like getElements(undefined)
  • document or window, like getElements(document)

getElements() always returns a plain Array of elements, empty if no elements are found.

Note: it does not actually verify that the resulting array contains only elements. The purpose of this module is to simplify the interpretation of an "elements" parameter and, if needed, you can use a isElement 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!

  • on-off: Add and remove multiple events on multiple elements in <1KB

License

MIT © Federico Brigante