Comment on Which side are you? Javascript or Typescript
SnowdenHeroOfOurTime@unilem.org 1 year agoWhere’d you get your time machine, that you obviously would’ve needed to set to 2008 to find anyone actual recommending jQuery?
Comment on Which side are you? Javascript or Typescript
SnowdenHeroOfOurTime@unilem.org 1 year agoWhere’d you get your time machine, that you obviously would’ve needed to set to 2008 to find anyone actual recommending jQuery?
severien@lemmy.world 1 year ago
It’s still the best API for imperative access to DOM.
SnowdenHeroOfOurTime@unilem.org 1 year ago
Do you need to support 15 year old browsers? Practically all the jQuery features I used (which was a lot) are now available in standard js
fidodo@lemm.ee 1 year ago
Even if you do, you can still use most modern js features with transpilation.
severien@lemmy.world 1 year ago
Yes, the features are there. Just the API is still horrible.
As an example, make a hidden element visible (extremely common imperative operation).
jQuery:
Native JavaScript:
I hope you’d agree that the native JS is certainly not an example of good API.
SnowdenHeroOfOurTime@unilem.org 1 year ago
That’s actually a great example of the shortcomings of jQuery. There are multiple ways to hide an element yet they standardized on one that often wouldn’t work.
Also you’re using an ancient method getElementById… I think visuals should still be controlled with css. So what is the right way to do that in modern js? document.querySelector(‘.some-name’).classList.add(‘hidden’) with that class defined in the css, with whatever makes sense, including maybe a css transition.
fidodo@lemm.ee 1 year ago
Why would you not want to be using a rendering library? Your code is basically storing your application state in the dom which will turn into a horrible mess as soon as you reach any actual level of complexity. I know first hand. I’m traumatized from having to maintain large jquery code bases in the 00s. No serious professional writes code like this anymore.
Also, your vanilla code isn’t modern. It should look more like this:
document.querySelector("#element").classList.toggle("hidden")
I could see not wanting to use a rendering library if you’re building a simple site on top of basic static HTML, but that’s not a serious discussion for industry professionals, and even still, jQuery is such a heavy dependency for saving some characters. If you find yourself using it so much you need the extra convenience then your site is already complicated enough that you should be using a rendering library with state management instead.