vanillajs-browser-helpers
Version:
Collection of convenience code snippets (helpers) that aims to make it a little easier to work with vanilla JS in the browser
22 lines (21 loc) • 694 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var isString_1 = __importDefault(require("vanillajs-helpers/isString"));
function findByQuery(elm, queries, first) {
if (isString_1.default(elm) || Array.isArray(elm)) {
first = queries;
queries = elm;
elm = document;
}
if (Array.isArray(queries)) {
queries = queries.join(',');
}
var q = queries;
return first
? elm.querySelector(q)
: Array.from(elm.querySelectorAll(q));
}
exports.default = findByQuery;