Короткий document.querySelector
function qs(selector, root) {
return (root || document).querySelector(selector);
}
function qsa(selector, root) {
return Array.prototype.slice.call(
(root || document).querySelectorAll(selector)
);
}
или так
const qs = (selector, root) => (root || document).querySelector(selector);
const qsa = (selector, root) => [
...(root || document).querySelectorAll(selector),
];
или так
const qs = (selector, root) => (root || document).querySelector(selector);
const qsa = (selector, root) =>
Array.from((root || document).querySelectorAll(selector));
пример использования
// один элемент
qs(".some-element");
// массив элементов
qsa(".some-elements").forEach(console.log);