You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
516 B
25 lines
516 B
"use strict";
|
|
|
|
const isDOMElement = require("./isDOMElement.js");
|
|
/**
|
|
* Find one or more DOM elements.
|
|
*
|
|
* @param {string|Node} element
|
|
* @returns {Node[]|null}
|
|
*/
|
|
|
|
|
|
function findAllDOMElements(element) {
|
|
if (typeof element === 'string') {
|
|
const elements = document.querySelectorAll(element);
|
|
return elements.length === 0 ? null : Array.from(elements);
|
|
}
|
|
|
|
if (typeof element === 'object' && isDOMElement(element)) {
|
|
return [element];
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
module.exports = findAllDOMElements;
|