Live data from Hacker News

I loved jQuery, and still do (2019)

withblue.ink

91–100 of 189 posts

Re: I loved jQuery, and still do (2019)

#91

Earlier quoted context omitted.

To use an example, I'd much rather do $(".elements").css("color", "red") versus var selector = document.getElementsByClassName('elements'); selector.style.color = 'red';

You can do const $ = document.querySelector; $('.elements').style.color = 'red'; Which is only marginally more verbose.

Though your alias definition needs a little extra, or the function loses its context and colling it will just result ":

  const $ = document.querySelector.bind(document);
or slightly less efficient, wrap in a function:

  const $ = function(x) { return document.querySelector(x) };
or if you want to be concise and don't need to support legacy IE:

  const $ = (x) => document.querySelector(x);
(and as pointed out already, you need querySelectorAll() and a loop for what jQuery does by default, though your example will work for a single element)

Re: I loved jQuery, and still do (2019)

#92
post #82
post #74

Earlier quoted context omitted.

I respectfully disagree. If you take 15 min to understand the basics it becomes trivially easy and the productivity you gain going forward is massive.

It's not going to take 15 minutes to understand WebPack and Parcel. Let's be a little more realistic. Sometimes you don't have the luxury of time and tools that you already know are going to get used, instead of new tools you don't.

https://parceljs.org/getting_started.html

If you have a use case as simple as the author is advocating, this only take about 15 minutes to grok. If it takes longer then you probably don't have enough front-end experience to productively contribute to this conversation. That is a little harsh, but the FUD in the JS world is incredible, mainly by people that have very little experience and understanding.

Re: I loved jQuery, and still do (2019)

#93
post #61

Every time anything about jQuery is posted, someone will inevitably post the "You might not need jQuery" site. [0] I look at that site and laugh. Is this supposed to be making the case ~against~ jQuery? Maybe the audience for that site are seasoned developers for whom the vanilla JS syntax is easily understood. Everybody else is going to look at those code snippets and think jQ is the way to go. For people that have…

That site is generally aiming at providing exact replacements, and quite a few of its examples are not great for various reasons: Some use a bad technique; e.g. “Empty” removes the first child repeatedly, which is O(n²) in many environments, rather than removing the last child repeatedly, which is O(n), or `el.innerHTML = ""` which is shorter and more efficient in general) Some suffer because they’re supporting IE wh…

> Fetch API would make it vastly shorter (`data = await (await fetch('/my/url')).json()`—as an aside, suffix await like Rust settled on is so much nicer: `data = fetch('/my/url').await.json().await`);

const data = await fetch('/my/url').then(r => r.json());

Re: I loved jQuery, and still do (2019)

#94

I had a big post but deleted it all. I can more concisely say this: The people here saying they still use it have so far demonstrated what I always say. If you're using jQuery, it's time to go back and relearn javascript. Most people should REALLY research the querySelector and querySelectorAll DOM methods. I've always felt that jQuery encourages you to let your skills stagnate and you don't learn what your code is a…

I've never really learned javascript in the first place - every time I try to learn I get caught up in a mix of versions of javascript(or ecmascript?), build systems, and just use "..." (coffeescript(lol), typescript, some node build system magic)

I build (barely) working websites with jquery and html and css though, having the "this is the one way jquery would do this and ignore all that other crap" value is high to me for that very reason - I work mostly on databases and having to learn the current spec every 2 years or whatever you web sickos are doing suuuuuuucks.

Re: I loved jQuery, and still do (2019)

#95
post #79
post #61

Every time anything about jQuery is posted, someone will inevitably post the "You might not need jQuery" site. [0] I look at that site and laugh. Is this supposed to be making the case ~against~ jQuery? Maybe the audience for that site are seasoned developers for whom the vanilla JS syntax is easily understood. Everybody else is going to look at those code snippets and think jQ is the way to go. For people that have…

I can see where you're coming from, but just wanted to add a counterpoint. I recently removed jQuery from a website, and the YMNNJQ website was one of the bits of info that gave me the nudge to do that. The website in question only used jQuery in a handful of places, it was one of the few third party libraries being used (so the % size savings was significant), and I'm fairly fluent with JS... The website simply hadn…

In your example, switching from jQuery was just a matter of personal preference. There's nothing wrong with that.

My original comment left out some context: on HN, a lot of the hostility to jQuery is either cultural or gatekeeping oriented. Cultural opposition is of the 'not invented here' variety, e.g. 'Why use Dropbox when you could do this w/ rsync? Gatekeeping-related opposition is where it's implied that you shouldn't call yourself a dev if you use jQuery and not vanilla JS.

That is the kind of discussion that happens nearly every time a link to YMNNJQ is dropped.

Re: I loved jQuery, and still do (2019)

#96
post #90

Earlier quoted context omitted.

I respectfully disagree if you have some other things to do in your free time than maintaining dependencies, trying to figure out why your project won't compile at all in 6 months of time while reporting 100 security issues, what will be the next change in webpack to will require to update both your config and some plugins, why does npm now cry for you to use a "--legacy-peer-deps" flags to nicely handle dependencies…

You are literally criticising Webpack for its best features. Identifying outdated libraries and potentially dangerous vulnerabilities is a huge plus for Webpack. Do you think just because you include a CDN lib in the global space vulnerabilities just magically go away? You also don't need to include packages that are poorly engineered and maintained. For what you do decide to use, you are getting visibility into the…

You are literally criticizing jQuery for its best features. Not having outdated libraries and potentially dangerous vulnerabilities is a huge plus for jQuery. Do you think just because you use a build tool for modules from all over the npm-verse that vulnerabilities just magically go away?

Re: I loved jQuery, and still do (2019)

#97
post #69

Yes Jquery does makes things easier than vanilla JS Best being $("#id") replacing document.getElementById("id"); Makes code look cleaner

You can define your own `$` function. This way you can have the clean code without the entire jQuery library function $(arg) { if (arg.charAt(0) == "#") { // HTML spec does not support ids to start with numbers [0] // (you may not need this conditional on your website) return document.getElementById(arg.slice(1)) } return document.querySelector(arg) } Using this function you can select your comment with $('#27677234'…

True, but jQuery does a lot more than just id selection with $!

You could just extend the function to detect '.' vs '#', and do a class selection as well. And then add all of the selectors, subselectors, etc. (similar to, but far more powerful than css3's selectors.) and if you go far enough, you reinvented zepto (but still a long way from jQuery)

(actually, since $ is basically synonymous with jQuery, it'd probably be better to choose a different function name. too bad you can't define it as #(id).)

Re: I loved jQuery, and still do (2019)

#98
post #90

Earlier quoted context omitted.

You are literally criticising Webpack for its best features. Identifying outdated libraries and potentially dangerous vulnerabilities is a huge plus for Webpack. Do you think just because you include a CDN lib in the global space vulnerabilities just magically go away? You also don't need to include packages that are poorly engineered and maintained. For what you do decide to use, you are getting visibility into the…

You are literally criticizing jQuery for its best features. Not having outdated libraries and potentially dangerous vulnerabilities is a huge plus for jQuery. Do you think just because you use a build tool for modules from all over the npm-verse that vulnerabilities just magically go away?

jQuery has had its share of dangerous vulnerabilities. https://snyk.io/vuln/npm:jquery

Re: I loved jQuery, and still do (2019)

#99

I finally learned some React a couple of months ago on the premise that as a designer, I needed a better understanding of the frameworks used by the developers I work with. I know React enforces some better practices that my spaghetti-jQuery of yore never followed, and that I was getting a crash course in those practices at the same time, but I was nonetheless surprised at just how slow I felt working in it! It gave…

Sounds like you're working on jQuery-sized apps, not React-sized. The problem is that many don't know the difference, and everything is React-sized, even apps that have no business being anything but server-rendered.

Re: I loved jQuery, and still do (2019)

#100
post #64

I agree with the author that jQuery was essential for the time. Abstracting away browser compatibility issues in the era of IE6 was a wonderful thing, for sure. The problem is jQuery has no business being used today unless you have to maintain legacy code. Even then I would deprecate jQuery wherever possible. Using jQuery for a "quick and dirty" application today is just terrible and it sends the message to green dev…

> a working Node.js environment

Sincere no-snark question from someone who's been out of the frontend game for a while: Why do I need Node in order to do "quick and dirty" frontend development?

(FTR I'm with you that jQuery is silly these days. Today's built-in web APIs do pretty much everything jQuery ever did.)

Post reply on HN