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?
Top comments (18)
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:
Can't argue with the above. Spot on!
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
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 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.
Bootstrap depends on it.
I second this. Most of my projects depend on Bootstrap
Bootstrap is stripping out JQuery in the next version and moving to vanilla JS
Well. I am looking how to make a Photo Gallery with coding, and I find some jQuery app for this. I know that I can do with Lightroom, with only CSS also, but which other library more updated can give me a photo gallery component? react? vue? angular?
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 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.
Some comments may only be visible to logged-in visitors. Sign in to view all comments.