UNPKG

453 BJavaScriptView Raw
1const isDOMElement = require('./isDOMElement')
2
3/**
4 * Find one or more DOM elements.
5 *
6 * @param {string} element
7 * @returns {Array|null}
8 */
9module.exports = function findAllDOMElements (element) {
10 if (typeof element === 'string') {
11 const elements = [].slice.call(document.querySelectorAll(element))
12 return elements.length > 0 ? elements : null
13 }
14
15 if (typeof element === 'object' && isDOMElement(element)) {
16 return [element]
17 }
18}