DEV Community

Cover image for Use this vanilla JS shortcut with $ function
Jaden Concord
Jaden Concord

Posted on

Use this vanilla JS shortcut with $ function

Jquery being 14 years old is still used by half of websites. The concept of Jquery is a great idea that is to simplify JS DOM manipulation, simplify AJAX and to make it easier to support IE. Now that AJAX is no longer needed as we can use the fetch API, and there is less of a need to support old IE browsers, there is no longer a real need for Jquery. But if I am writing vanilla JS I dont want to write document.querySelector every single time.

var $ = document.querySelector
var $$ = document.querySelectorAll
Enter fullscreen mode Exit fullscreen mode

Use these function shortcuts and it will make life much easier.

Top comments (3)

Collapse
 
shadowtime2000 profile image
shadowtime2000

Actually, some browsers already inject this into the global scope if there is no library or code that is setting $ or $$.

Collapse
 
jadenconcord profile image
Jaden Concord

interesting

Collapse
 
ben profile image
Ben Halpern

I like this.

Some comments may only be visible to logged-in visitors. Sign in to view all comments.