$ sign to pick up an element and do stuff to it.
document.querySelector multiple times in an application. Well, guess what, there's an easy way to just bind that
$ sign to your document's
Here's how you go about it.
const $ = document.querySelector.bind(document); const $$ = document.querySelectorAll.bind(document);
Now you can use the following:
// Change the background color of a class. $('.class').style.background="#BADA55"; // Change the inner HTML of an ID. $('#id').innerHTML="<span>Cool beans!</span>"; // Select all images on the webpage. $$('img') // Print the image addresses for all the images on a webpage. $$('img').forEach(img => console.log(img.src))
Liquid error: internal
Use your code for good and have fun! :)