381 points · by petecooper · 2w ago · 204 comments
One thing I still regularly use jQuery for, though, that's rarely mentioned, is its event model. You can put a listener on any object, not just things in the DOM. Any data object can trigger an event. This is incredibly powerful for isolating logic from DOM elements and events. A frequent use case is for DOM elements to contain a reference to a data object that may be replicated elsewhere on the page. The data object sets up and tears down visual elements, listening for interaction, then dispatches a custom event. Your core logic listens for events on the data object instead of on every individual element that might refer to it. I usually delegate the draw routine for e.g. html snippets of a card or an interactive element to the data object itself in a draw() function that returns a string which incidentally jQuery handles quite nicely inserting into the DOM without needing to explicitly call createElement.
I wrote my own implementation of this a long time ago, but in the end, that feature plus the other ergonomics of jQuery still make it my go-to today over vanilla js. And pretty much everything I write is without any reactive framework (other than my own vanilla component/templating/remoting system), so the overhead is barely noticeable.
Not just as a framework but its documentation is also probably an inspiration for later libs. It was the first site for me where you could see the code and result together on the same page at the same place. And the discoverability of widgets was also great and exciting in a way.
Just open the firebug console, and try the examples for selectors, callbacks etc.
https://developer.mozilla.org/en-US/docs/Web/API/EventTarget
But by this, I don't wanna say you should. It's also of course newer than what jQuery did, and might be inspired by it (just like Sizzle influenced the QuerySelector API, and CoffeeScript influenced arrow functions).
* brief snapshots on what’s interesting, valuable and good about some random thing
thx for sharing and taking the time to write it noduerme
That was, and still is, rare! And in a time without type checking and bundling, it was vital. Match your parentheses and quotes, and your jquery code might not find what you want, but it would (likely) not throw exceptions.
For those unfamiliar, I recommend looking at https://github.com/DefinitelyTyped/DefinitelyTyped/blob/mast... and searching for the 201 instances of
: this
in that file. A remarkably fluent API. We could all be so elegant.That'd be an interesting alternative reality!
What ended up happening is that I'm writing (having it written by agents) react like everybody else.
I had to use it on a legacy site recently and forgot how nice it was and it all just came back to me too. Didn’t need docs either. That’s a sign of a very well designed lib
A TC39 Stage 2 proposal adds this into the language itself with the pipeline `|>` operator. [2]
Maybe not precisely the same from a technical point of view but is it just pendantry to argue against someone referring to it as a fluent interface? Happy to learn and to be corrected if required.
Which true is not per se fluent interfaces, but it reads similarly.
And "fluent" -- as the name suggests -- has a lot to do with how it reads, left-to-right with no intermediate variables.
$('#selector').html('new <strong>text</strong>').attr('foo', 'bar');
They have the small surface area of jQuery, but still aim for component-based reactivity and SSR-when-possible which just aligns more with the mental model and development preferences that have developed from the whole world of React/Next and similar.
But to answer your question: Easier to read, easier to write, easier to understand.
code has to be human centric and not influencer centric. Awww, this is not so chic anymore. If you use this you are a peasant, BUT if you use this, well, you are king.
Jquery is only not relevant if you're living in a tech bubble that demands that "new, shiny" is the only thing that could possibly be relevant.
But still everywhere!
Software has a way of sticking around.
I hope https://github.com/tc39/proposal-pipeline-operator and perhaps also https://github.com/tc39/proposal-do-expressions will put it to rest.
jQuery made the decision to do this, not JavaScript.
And while most of the use cases for jQuery have long since died out with things like classList, querySelector, etc, I do feel there's probably value in a framework that focuses on minor enhancements to a site rather than being the backbone of the whole thing. Like if you want a React or Angular or Vue equivalent, something like jQuery would be a terrible choice, but a lot of sites are static ones where the only scripting needed would be for minor things like dropdown menus or slideshows, and I can see a modern, lean library like this being a decent choice there.
Very much so. jQuery had 2 major selling points - (1) browser polyfills and (2) conciseness, as per their slogan, "Write less, do more". It seems (2) has been largely forgotten since (1) has been rendered obsolete. Its idea of running functions on a collection often made scripts end up at one-third to one-half of the equivalent vanilla JS, which needs loops to do the same thing.
When most code is and will be written by AI, why would I sacrifice performance for syntactic sugar?
It's sort of the same sort of less-is-more mindset of jQuery but for the modern reactive-component model - intentionally small, allows SSR swapping when possible (like HTMX), and adds the layers of reactivity that can still only be reasonably done with frontend scripting.
Probably more than use React, by total domains alone. It's a bit like WordPress; so ubiquitous you forget it's even there, and with a long tail that will outlive many people reading this.
Approximately 64% of all websites—or roughly 67 million live domains—currently use jQuery.
That's why I'm surprised to see still being maintained... ever since Chromium basically won the browser wars and pretty much everything's standardized now, it almost feels like it's lived out its usefulness.
I also want to say I remember it being a bit bloated too. I did work for a client who had several users live in very remote areas where every bit of bandwidth was precious, and I wanted to say that one of the issues was with jQuery. For some reason the "slim" version didn't work for the use case either. This is going off of memory and was probably 15 years ago, so I could be entirely wrong.
There's no denying it's prevalence though. Heck, datatables.net only recently phased out the jQuery dependency in April... of this year!
const xhr = new XMLHttpRequest();
let lastLength = 0;
xhr.addEventListener("progress", () => {
const chunk = xhr.responseText.substring(lastLength);
lastLength = xhr.responseText.length;
console.log("New data:", chunk);
});
xhr.open("GET", "/stream");
xhr.send();
-------------------The modern fetch API is better though because it's a Promises API and it can stream as raw bytes, not characters:
const response = await fetch("/stream");
const reader = response.body.getReader();
while (true) {
const { value, done } = await reader.read();
if (done) {
console.log("Finished");
break;
}
console.log("Received", value.length, "bytes");
} const response = await fetch("/stream");
for await (const value of response.body) {
console.log("Received", value.length, "bytes");
}
console.log("Finished")I wasn't talking about version 4.1, this would have been version 1.x (maybe 1.5... it was ~15 years ago), and the issue was bandwidth usage for uber remote users. There were all sorts of tricks I remember implementing to get that project over the finish line, but one of them was definitely yoinking jQuery out of the project, despite me being a big advocate for the library.
$('.mispell').hide()
No error. Just silent. This is why jQuery is not a good library other than for 2010 cross-browser development.
Wouldn't you notice with your eyes the thing didn't hide as expected?
Silent errors are by design I recall. Confirming with nearest AI... yep and a good explanation, please excuse the AI paste:
A selector is treated like a query that returns a collection (which can legitimately be empty). Applying an action to zero items isn’t an error it’s just a no-op. This is similar to how CSS works (no harm if no .foo) or how many collection methods work in other languages.I do frequently, partially because I tend to branch new projects from old ones, and the old ones often used jQuery. Updating everything to vanilla would be a lot of effort for little gain.
I wonder how it feels for the original jQuery developers. They solved some big problems, then their ideas were just copied into Javascript itself, and their pioneering library became decried as old and irrelevant--even though it works just fine, and still solves some niche problems.
I'm a jquery fanboy, and enjoyed seeing native JS copy good patterns, it only confirms jquery were onto something.
All good, native JS is now better because it copied. Although $('.foo').hide() wasn't copied but should have been. Hiding stuff is an archetypal biological need!
Nothing stopping Jquery 5 and beyond doing something different like, I dunno, "game enginey" helper things, IOT tricks, it can do whatever it wants now.
W3Counter shows Around 0.07% of market share.
I wonder why IE11 is still being used or even a requirement? Especially in today's world where security could be a very serious issue.
Only on Windows 10 and 11. It still runs as it always did on previous Windowses.
That being said it's no longer that useful for dealing with browser incompatibilities or for remote calls. I end up using a stripped version or something like https://github.com/fabiospampinato/cash
What vanilla is obviously unbeatable for is, you're writing a snippet of JS that you can hand anyone[1] to run with no dependency requirements. Some codebases may be explicitly incompatible with JQ, so knowing how to do all the JQ basics "vanilla" is an important skill so you don't have to bring in a "big" (relatively, I mean) library to support a 7-line function.
[1] for example, an embed code, an analytics tag, or a script to customize the markup on a page.
Now that ES and CSS5 are everywhere, the biggest feature of jQuery is list comprehensions on components. Data is also still good IMO but mostly the comprehensions.
jQuery decided that calling a function on an empty list should be a no-op, but my experience using it for a very interactive application was that nearly every time we wanted something to definitely happen or it was a bug, and the handful of times where an empty list was expected were easy to anticipate.
Because the general problem was that making a selector that continued to work correctly as features were added was a black art. Two of us wrote selectors that almost always worked, the rest of the team wrote ones that almost always broke and only very slowly onboarded our advice (also all of the stuff they already wrote was a ticking time bomb).
New features and especially tweaking the DOM tree to stay compatible with old corporate browsers would break existing functionality about a quarter of the time someone had to change the DOM structure to close a ticket and it was infuriating.
So what I want is that if .hide() is a no-op, throw an exception. And if I'm implementing the 'select all/unselect all' feature I know that the list might be empty, I can add a flag or wrap a conditional around it so I ignore the error.
Because those functions work on a very tight chunk of DOM that changes structure much much slower than the overall document structure, and also that code is quite close to the point of change if someone does change it, so has better chances of being remembered than something in the header.
You can "just" add these methods and ban raw `find` with linting?
There's a lot of things you can do when you're a sole proprietor on a project. But other developers have opinions and they expect them to be respected as much as you expect them to respect yours.
Can you think of the last project where you got everything your way? I can't, and I have a reputation of being pretty insistent about people trying my suggestions before they say no.
The three biggest problems with JQuery UI:
1) The quality wasn't anywhere near as good as jquery, so many times I had to correct people whose opinion of jquery encompassed jquery UI
2) They declared bankruptcy on managing the call tree spaghetti and decided to rewrite the entire thing one component at a time, which meant that simultaneously some things were changing a lot and everything else they refused to entertain bug reports on the parts that were still in the queue.
3) It took them three times as long to do the work as they expected, and the original ask was already a bit much.
Angular became a thing before they finished the work.
Unrelated, but it blew my mind when I learned that Elrond is half-man.
There is a ton of stuff you can do now with JS directly that JQuery had to compensate for, that's why GitHub spent the effort to move off of JQ years ago.
CSS and JS has come a long way. I will even venture out to say that UI development does not suck these days, it's even a little enjoyable. You no longer have to spend 3 hours vertically aligning text in a div and then test it in four different browsers.
jQuery really changed the game by letting an average developer actually use Javascript to enhance a web page. Granted I want to go back to the days when no one used Javascript and the Internet was a giant mess of terrible 8bit graphics and anonymous friends, but thank you jQuery for everything you did. It is not your fault humans are terrible.
So often was the case that the two ran together, especially with IE6.
Did not know this library is still being maintained
There's a list of large legacy sites that use jquery behind that link, including:
* Microsoft.com * Pinterest.com * Adobe.com * Yahoo.com * Wordpress.org * Digicert.com * Samsung.com * Archive.org
Until people stop making sites with Wordpress, JQuery will continue to live on for a while.
FAA ground stop: initiated
Microsoft 365: down
United Airlines: down
Github actions: down
Apple: down
Nvidia CEO: owned
Clandestine NSA network: down
jQuery: 4.1.0 released :)You just don't need this. No jquery, no react, no tailwind, no fowntawesome, no external libs, no malware attack vectors, no waiting for a new update that never comes. It is all poison, just don't drink it and you'll be fine
So is AI.