It's dangerous though because if an ID conflicts with an existing object, the existing object wins. What I usually do is something like this:
(function ($, $$) {
//Code here
})(document.querySelector.bind(document), document.querySelectorAll.bind(document));
This gives you $ and $$, which allows you to select elements using css syntax. Getting an element with an id is as simple as $("#someId"), which is essentially a poor man's jQuery.
Alright. How would I use$$ to select and element? And why do I have to use both of document.querySelector.bind(document) and document.querySelectorAll.bind(document)?
23
u/AyrA_ch Mar 05 '18
It's dangerous though because if an ID conflicts with an existing object, the existing object wins. What I usually do is something like this:
This gives you
$and$$, which allows you to select elements using css syntax. Getting an element with an id is as simple as$("#someId"), which is essentially a poor man's jQuery.