Why do you use jQuery in 2019?

twitter logo github logo ・1 min read

JavaScript has matured a lot in the last years, and IMHO, jQuery has become irrelevant for me.

But that's not a reality for every developer, as the Stack Overflow Developer Survey Results 2019 has shown that 48.7% of the developers still use jQuery.

With a much easier and mature JavaScript, why do you use jQuery? What are the uses that vanilla JS can't do easily?

twitter logo DISCUSS (13)
markdown guide
 

I have no evidence to back this up, but I'd be willing to guess that it's not about what jQuery does that vanilla can't do easily, so much as one of the following:

  • Supporting a legacy codebase
  • Not knowing that vanillaJS has feature {x}
  • Familiarity with JQuery - For example: If you had to choose between looking up how to do something in vanilla or already knowing how to do it in JQuery, which would you choose?
 
 

There are still quite a lot of things that jQuery provides that are not one-liners in Vanilla JS. For example - serialize, and event delegation with on. And then dozens of other bug fixes and conveniences.

Of course, you can implement these things yourself in Javascript, but why should you do that? Are you sure that copy-pasted code you found on the internet really works correctly on all browsers, or was it an 80% solution that got lots of upvotes on StackOverflow by people that didn't test it very thoroughly? Do you want to have to learn a hundred different browser gotchas the hard way, and is that really a good use of your time?

 

It is in place in a legacy app, but I have been trying to use more standard JavaScript. I came across this GitHub repo with some good examples to help in going from jQuery to standard JavaScript github.com/nefe/You-Dont-Need-jQuery

 

It still has some advantages. If you do

const a = document.querySelector(`a`)

And then try to use a, it will throw an exception. With jQuery it just fails silently. This can be a pro or a con depending on your use case.

Also a good thing to use it for is when you receive a bunch of HTML in a string from a server and want to insert it into your document.

 

I would say legacy codebases. Mostly WordPress themes with jQuery libraries. I still enjoy using jQuery for quick fixes and getting stuff done easily. If it is already in a project, then I see no reason not to use it. Otherwise if I can I will use just vanilla and Vue.

 

Legacy codebase. The library is still loaded up on every page. May as well use it, and mixing up querySelectorAll() and $() in the same application sounds like a recipe for disaster.

It's just not a priority to do massive rewrites just to expunge jQuery. If I started a project from scratch today, no, I wouldn't use it.

 

jQuery is more than just a bunch of features. It is also an opinion on how to do things. For example if you want to hide an element in vanilla JS do you use visibility or display?

For someone who has used jQuery for a long time, pulling in an 80K library and calling $('elm').hide() just makes sense. If jQuery is still supported, they get the performance they need and behavior they expect why should they change it? Wouldn't it make more sense to spend their time focusing on delivering value to their users?

jQuery also has a rich ecosystem of plugins an extensions that would be a pain to reproduce if you decided to migrate everything to vanilla js. Again you have to decide what is the most valuable use of your time.

It is understandable why people get excited about new technology but sometimes we forget why we are doing it. I would be more likely to shift from jQuery to a framework for code organization and maintainability than I would to vanilla js just because I can. The users of your site don't care if you use $() or document.querySelector.

 

I use jQuery because it is a library that performs very well and helps me do things in a pragmatic way. No doubt that JavaScript has gotten better but there are things that can be done via jQuery which are more elegant and easier to maintain. You write and application once and maintain it forever. There is nothing wrong with jQuery in 2019 or beyond. Web developers use dozens of libraries to make their lives easier. jQuery is no different in this regard.

It's fine if you can or want to write applications without jQuery but don't expect a gold star just because you didn't.

 

We sell most of our projects based on a system that uses jQuery. So yeah, legacy codebase.

 
 

48.7% of the developers still use jQuery

Years and years of being in dominance.

But I was still surprised by this number in 2019!

Classic DEV Post from Oct 8 '18

Hiring process of your dreams

What would be a hiring process you would love?

Vinicius Brasil profile image
I like to understand how things work.

Read more long-form software content.

Sign up (for free)

Become a better software developer.