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…
jQuery 4.0 99% Complete
21–30 of 47 posts
Re: jQuery 4.0 99% Complete
#22Earlier 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"));
Re: jQuery 4.0 99% Complete
#23It 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…
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
#24Re: jQuery 4.0 99% Complete
#25People 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
#26Love it how the homepage hasn't change in years.
Re: jQuery 4.0 99% Complete
#27Earlier 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…
Re: jQuery 4.0 99% Complete
#28Earlier 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"));
Re: jQuery 4.0 99% Complete
#29Is 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/
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
#30It 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…
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.