DEV Community

Abde Lazize
Abde Lazize

Posted on • Edited on

3 1

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)

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay