DEV Community

Discussion on: Who still regularly uses jQuery?

Collapse
 
jackharner profile image
Jack Harner 🚀

I use it. 🙋‍♂️

  • Most of my work lately has been in WordPress and jQuery is built in.
  • $("#id") is easier to type than document.getElementById("id").

While I'm still learning more and more about React, I plan on eventually figuring out the setup for a React Frontend with a WordPress backend. Frameworks like Frontity make that connection a whole lot easier.

Collapse
 
dwilmer profile image
Daan Wilmer

I think your first reason is the main cause of that eighty-something percentage of websites. There is a huge number of websites based on wordpress, and they all have jQuery.

I personally write a mix of vanilla JS and jQuery when writing javascript in wordpress. In most cases I prefer vanilla JS, but sometimes jQuery just has features ready that I need and... it's just there, you know?

Collapse
 
pavelloz profile image
Paweł Kowalski

Fun fact

If you need to access element via ID, then you can skip functions altogether.

Having element: <div id="my-element"></div> you can access it via window["my-element"] ;-)

Collapse
 
jackharner profile image
Jack Harner 🚀

That is a fun little fact.

Good to know!

Collapse
 
karataev profile image
Eugene Karataev

It's not always safe to use this trick to query an element. For example, if you have <div id="alert" /> on a page, accessing window['alert'] will not return the element you're looking for.

Collapse
 
alangdm profile image
Alan Dávalos

If you really just love $() you can add this line to your JS

const $ = selector => document.querySelector(selector);
Enter fullscreen mode Exit fullscreen mode

or this one if you don't want to compile to es5

function $(selector) {
    return document.querySelector(selector);
}
Enter fullscreen mode Exit fullscreen mode

And remove JQuery as it's overkill to have your user download a whole library if that's all you want XD

Collapse
 
afewminutesofcode profile image
Aaron

Thats a great tip Alan! I agree that it is overkill and I haven't used it for a number of years. I think when I stopped using it I became a better developer and got a much better understanding of js.

Collapse
 
mateus_vahl profile image
Mateus Vahl
const $ = document.querySelectorAll.bind(document)