DEV Community

Abde Lazize
Abde Lazize

Posted on • Edited on

Using $ to select HTML elements without using jquery

you want to use the dollar sign $ to select HTML elements but you don't want to use Jquery ?
All you need to do is this:

const $ = document.querySelector.bind(document);
const $$ = document.querySelectorAll.bind(document)
Enter fullscreen mode Exit fullscreen mode

Now let say we have a div with the class container, you can select it like this:

const container = $(".container");
Enter fullscreen mode Exit fullscreen mode

Now lets say we have multiple inputs with the class input and we want to select all of them, you can do it like this.

const inputs = $$(".input");
Enter fullscreen mode Exit fullscreen mode

If you found this post useful give it a like.

Top comments (0)