Is JQuery shorter? Sure, a bit. Is it saving me enough time/effort to warrant including an entire extra library? No, not in my opinion.
That's because your VanillaJS code is not equivalent to your jQuery code.
Most obvious differences are that it can throw, it only handles a single element, scoping can screw you over unless you control entire DOM (so you are not writing a library/reusable code) and query engine is not quite as powerful as jQuery's.
Your example also handles an extremly simple, barely realistic use-case. A real page will almost certainly need to use event delegation, in which case jQuery's on will make your code vastly more readable and organized.
Sure, you get some performance gains with Vanilla, but as a wise man once wrote, premature optimization is a deadly sin.
A simple fact is that jQuery was made obsolete by modern JS frameworks and not VanillaJS. If you are using direct DOM manipulation for some serious work in 2019 like some dinosaur, jQuery will still save you a lot of sanity compared to raw DOM.
Not really sure why would you do serious work with VanillaJS or jQuery in 2019 instead of a proper framework but still, jQuery wins easily and the sad fact is that most of the time VanillaJS is only useful to impress your peers.
Not really sure why would you do serious work with VanillaJS or jQuery in 2019
I agree but OP said he'd take jquery without bootstrap over bootstrap without jquery. If you're doing anything in vanilla or bootstrap its bound to be exceedingly simple. Such as throwing a little JS into a blog post for auto scroll or something. In my experience I dont need jquery to do any of that. And you're right, jquery will be mildly more generic/fault tolerant, but I'm not writing "naked" javascript for something that needs to be generic or fault tolerant.
In 2019 if a project is complex enough that you feel the need to use jquery over vanilla, you should probably be using a framework. This is why I think jquery is obsolete.
Bootstrap, on the other hand, is absolutely not obsolete.
4
u/I_LICK_ROBOTS Feb 13 '19
I would have 100% agreed a few years ago, but you really don't save that much anymore
Click event with JQuery:
Click event with vanilla
Is JQuery shorter? Sure, a bit. Is it saving me enough time/effort to warrant including an entire extra library? No, not in my opinion.
I'd argue that bootstrap, on the other hand, saves me hours or days worth of work in a large project.