3 ms·
I add the parent element to mine const $ = (selector, parent = document) => parent.querySelector(selector); const $$ = (selector, parent = document) =>
by joeframbach 4y ago
I add the parent element to mine
const $ = (selector, parent = document) => parent.querySelector(selector);
const $$ = (selector, parent = document) => parent.querySelectorAll(selector);
- abdusco 4y agoThis is the way. In addition to `$` and `$$`, I usually have `$h` for creating elements: /** * @param {string} name * @param {HTMLElement.prototype} props * @param {Array<HTMLElement|string>} children * @return HTMLElement */ function $h(name = 'div', props = {}, children = []) { const el = document.createElement(name); Object.assign(el, props); el.append(...children); return el; }