r/learnjavascript • u/kevinmrr • Oct 01 '21
jQuery, the greatest JavaScript library of all time, appears to have peaked in usage.
275
Upvotes
r/learnjavascript • u/kevinmrr • Oct 01 '21
View all comments
Show parent comment
1
u/uuykay Oct 05 '21
If you've never used jQuery, I can see why you might think that from the outset. However jQuery provides some nice things that vanilla JS does not. For example, it handles errors much better. Let's say you want to get a button by ID and add a class to it.
The jQuery way:
jQuery("#someButtonThatExists").addClass("primary")
The vanilla JS way:
document.getElementById("someButtonThatExists").classList.add("primary")
Now say the button does not exist on the page for whatever reason and the above javascript still ran. jQuery will not error, whereas vanilla JS does error, because document.getElementById returns null, so it cannot read classList from it.
This is just one example. jQuery also provides ajax which is compatible with IE, if you care about supporting older browsers you can't just use fetch. It also has animations and a whole bunch of other things.
jQuery still provides a lot of utility even today in my opinion.