Live data from Hacker News

jQuery 4.0 99% Complete

github.com

21–30 of 47 posts

Re: jQuery 4.0 99% Complete

#21
post #10

It has been a long time since I used jQuery. What exactly is the usecase today? Is it just syntactic sugar or has it changed significantly?

I think the main use case today is the dom traversal API. It makes operations like "add the 'error' class to all elements in the form" simple: $('#some-form').find('input').addClass('error') Obviously you can do this in vanilla JS, but it's more cumbersome so you'll probably end up rewriting your own less complete version of jquery. There is some value to using a well worn library with public documentation that other…

I almost always fall back to jq if it's loaded, vanilla js APIs are so annoying.

Re: jQuery 4.0 99% Complete

#22
post #20

Earlier quoted context omitted.

I think the main use case today is the dom traversal API. It makes operations like "add the 'error' class to all elements in the form" simple: $('#some-form').find('input').addClass('error') Obviously you can do this in vanilla JS, but it's more cumbersome so you'll probably end up rewriting your own less complete version of jquery. There is some value to using a well worn library with public documentation that other…

Is it that hard to: document.querySelectorAll("#some-form input").forEach(e => e.classList.add("error"));

[deleted]

Re: jQuery 4.0 99% Complete

#23
post #10

It has been a long time since I used jQuery. What exactly is the usecase today? Is it just syntactic sugar or has it changed significantly?

I think the main use case today is the dom traversal API. It makes operations like "add the 'error' class to all elements in the form" simple: $('#some-form').find('input').addClass('error') Obviously you can do this in vanilla JS, but it's more cumbersome so you'll probably end up rewriting your own less complete version of jquery. There is some value to using a well worn library with public documentation that other…

Mostly off the top of my head:

    document.getElementById('some-form').getElementsByTagName('input').forEach(i => i.classList.add('error'))
It is a little more verbose but it isn't that much more cumbersome today.

That's also doing things "the right way" and not do-all selectors, but that option exists now, too:

    document.querySelectorAll('#some-form > input').forEach(i => i.classList.add('error'))
If you want to make it a little less verbose:

   const $ = document.querySelectorAll
   const addClass = (className) => (item) => item.classList.add(className)
   $('#some-form > input').forEach(addClass('error'))

Re: jQuery 4.0 99% Complete

#24
The younglings don't seem to appreciate what a godsend jQuery was back in the day, it gave you a decent API that worked on all browsers, including IE6. HTMX nowadays is giving off a similar vibe, it gets you 95% there without modern JS insanity/complexity.

Re: jQuery 4.0 99% Complete

#25
I use jQuery for JS for the same reason I use Twig for PHP.....it's way simpler to write functions to get things done.

People keep telling me to switch to ES6 but I'm never upgrading. Why would I? jQuery just feels like a good pair of jeans.

Re: jQuery 4.0 99% Complete

#27

Earlier quoted context omitted.

I think the main use case today is the dom traversal API. It makes operations like "add the 'error' class to all elements in the form" simple: $('#some-form').find('input').addClass('error') Obviously you can do this in vanilla JS, but it's more cumbersome so you'll probably end up rewriting your own less complete version of jquery. There is some value to using a well worn library with public documentation that other…

Mostly off the top of my head: document.getElementById('some-form').getElementsByTagName('input').forEach(i => i.classList.add('error')) It is a little more verbose but it isn't that much more cumbersome today. That's also doing things "the right way" and not do-all selectors, but that option exists now, too: document.querySelectorAll('#some-form > input').forEach(i => i.classList.add('error')) If you want to make it…

Love the syntax in the last example, you should make it into a library!

Re: jQuery 4.0 99% Complete

#28
post #20

Earlier quoted context omitted.

I think the main use case today is the dom traversal API. It makes operations like "add the 'error' class to all elements in the form" simple: $('#some-form').find('input').addClass('error') Obviously you can do this in vanilla JS, but it's more cumbersome so you'll probably end up rewriting your own less complete version of jquery. There is some value to using a well worn library with public documentation that other…

Is it that hard to: document.querySelectorAll("#some-form input").forEach(e => e.classList.add("error"));

No it's not

Re: jQuery 4.0 99% Complete

#29
post #15
post #12

Is there some kind of summary available somewhere of what features are “unique” to jQuery (or at least significantly easier), and what features are now generally available as vanilla JS or CSS? I’m not a JS developer and I just have a basic understanding of what jQuery is used for, so I’d be interested in seeing some kind of historical timeline, both to better understand why jQuery was originally created, and to unde…

https://youmightnotneedjquery.com/

Quite a feel of those seem like while you don't need jQuery (so the site is indeed actually named), it's still often easier. Doubly so when you consider that the non-jQuery methods don't always chain together.

Admittedly I'm usually using it in places where loading the extra library is not an issue, so if you're really going for slimline, then sure.

Re: jQuery 4.0 99% Complete

#30
post #10

It has been a long time since I used jQuery. What exactly is the usecase today? Is it just syntactic sugar or has it changed significantly?

I think the main use case today is the dom traversal API. It makes operations like "add the 'error' class to all elements in the form" simple: $('#some-form').find('input').addClass('error') Obviously you can do this in vanilla JS, but it's more cumbersome so you'll probably end up rewriting your own less complete version of jquery. There is some value to using a well worn library with public documentation that other…

This won't throw an error if the form ID changes. Which is to be expected for working on collections. But I don't like this being the default, exactly because of cases like this.

Same thing of course applies to people who throw around the optional chaining operator without thinking to please TS.

Or would apply if one used a single selector here and document.querySelectorAll

The needless chaining here is a typical example of misleading jQuery code though. Looks as if it was there to prevent this issue.

Post reply on HN