by PaulRobinson · 2y ago · 0 comments
I was thinking about doing some stuff for a hobby project recently and as a mostly back-end engineer, I am very out of date for most front-end code. I did a scout around, and didn't feel too impressed.
Finally last week I was thinking "I wonder what happened to jQuery", and there it was. Just as it ever was. Updated, freshened up, but completely recognisable and completely usable.
Is it new and shiny and full of awesome features? No. Do I understand it? Yes. Are there plugins for most things I need? Sure.
I feel old, but I'd rather make progress with something unfashionable than have to deal with deprecation and learning curves with something fashionable.
Hide Show
```
$(".box").hide();
$(".box").show();
vs
document.querySelector(".box").style.display = "none";
document.querySelector(".box").style.display = "block";
``` Both work. The first is more clear
const $ = document.querySelector.bind(document);
$('.box').hidden = true;
$('.box').hidden = false;
```
jQuery is designed not to fail. So if there's no `.box` on the page, jQuery will not do anything.
`querySelector` may return null, so `$('.box').hidden` will hard break your page if you're not careful enough
2. `$('.box').hide()` is just one such example.
The hilarious https://youmightnotneedjquery.com/ shows that jQuery remains more consistent, concise, and composable than most things in modern browser APIs
For development, browsers and version managers/containers are stable enough that you won't be on a deprecation treadmill. Any pressure would come from including other people on the project, which you'd get even more of with jQuery.
I appreciate the 'do what works' mindset quite a bit but I hope you'll give a modern reactive framework or library a try; I'm glad I made the change.
Mithril if you just want to drop in want a tiny, complete reactive library that doesn't require a build step--this one is most like what you might end up creating in a large jQuery app. You can understand everything from the homepage. https://mithril.js.org/
HTMX if you really like HTML conventions. This doesn't feel jQuery-like and depends on your approach to your server app. https://htmx.org/
If you were to pick just one, I think Vue would be the most rewarding.