3 ms·
Though your alias definition needs a little extra, or the function loses its context and colling it will just result ": const $ = document.querySelector.bind
by dspillett 5y ago
Though your alias definition needs a little extra, or the function loses its context and colling it will just result ":
const $ = document.querySelector.bind(document);
or slightly less efficient, wrap in a function:
const $ = function(x) { return document.querySelector(x) };
or if you want to be concise and don't need to support legacy IE:
const $ = (x) => document.querySelector(x);
(and as pointed out already, you need querySelectorAll() and a loop for what jQuery does by default, though your example will work for a single element)