3 ms·
I'm genuinely curious - what features does jQuery have that make it better than modern vanilla JS? Back in the day the vanilla DOM APIs were bad, so jQuery was
by Hasu 3y ago
I'm genuinely curious - what features does jQuery have that make it better than modern vanilla JS? Back in the day the vanilla DOM APIs were bad, so jQuery was great, but I haven't felt the need to reach for it in ages.
- ipaddr 3y agoBetter and shorter syntax, plugins, ecosystem. 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
- jacobr 3y ago``` const $ = document.querySelector.bind(document); $('.box').hidden = true; $('.box').hidden = false; ```
- troupo 3y ago1. Not really. 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/ https://youmightnotneedjquery.com/ shows that jQuery remains more consistent, concise, and composable than most things in modern browser APIs
- just_testing 3y agojumping in on this bandwagon... I sometimes look https://youmightnotneedjquery.com https://youmightnotneedjquery.com when I forget how to do something with jQuery. Also, do you know if there is a jQuery-like that actually throws exceptions? Having `$('.box').hide()` tell me there is no `.box` would be pretty useful.