Live data from Hacker News

I loved jQuery, and still do (2019)

withblue.ink

61–70 of 189 posts

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

#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 struggled through HTML and CSS, there is perhaps nothing more deflating than to realize that even basic UI interactivity requires JS. But with jQuery the code snippets needed are short and understandable. Vanilla JS in comparison looks like an entirely different language.

[0] http://youmightnotneedjquery.com/

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

#62

I've depended on jQuery, not a strictly front end designer myself but have done a bit of client side dev the past 20 years. If I had a choice, I'd go with one of the reactive libraries, I've used Vue. For me, if you're relying on Javascript IMO it gets the job done quicker. It'd be interesting to see what jquery is used for in aggregation of all its usage. For me it was always selecting element(s) and XHR requests. W…

I've never been a UI dev, but have frequently been forced to put a UI as a PoC that becomes production UI. ugh. I had always turned to JQuery just for the browser compatibility aspect. I got out of the game for a few years and have recently gotten back on the that horse. I turned to JQuery as that's what I knew. Now that supporting IE is no longer a thing, and since modern JS essentially includes the missing pieces J…

>replacing

They're not so comparable TBH, the reactive element is the key difference. I can simply create logic, apply changes to the input data and the UI is updated. With jQuery you have to update the UI and data, far less easy. Point I was making is that if you're site relies on JS, I'd pick a reactive framework to do the heavy lifting.

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

#63

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…

Have fun when your page randomly gets visited by IE7 running behind some ancient corporate firewall.

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

#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 devs that jQuery code slinging is a skill worth having.

If you like quick and dirty, just make sure you have a working Node.js environment and generate a simple project that supports Webpack or Parcel. You will get all the advantages of Babel and Polyfills (if you need them) with little to no effort.

jQuery has no value except for maintaining legacy code. jQuery was useful back in the day (and John Resig had the best solution), but I don't love it anymore. In fact, I have serious judgements of the devs that use it that should know better.

Edit: I should note that jQuery is bad because it has no state management and you cannot easily track side-effects. I would much rather see someone use something like Svelte and construct the functionality with modern best practices while keeping a very small footprint.

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

#65
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…

> If you like quick and dirty, just make sure you have a working Node.js environment and generate a simple project that supports Webpack or Parcel

There’s nothing quick or easy about these steps. Linking to a jQuery CDN and getting working code immediately is easy.

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

#66

Earlier quoted context omitted.

Can you elaborate on what JQuery does for you that you can't do with modern JS features such as fetch and query selectors?

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

The jQuery example is good, but the "vanilla" example is cleaner and simpler: the class name isn't decorated with a dot, the CSS property name is not quoted, $ might be hijacked or overloaded, it is not obvious (compared to a plain assignment) that css is a setter and what arguments it takes.

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

#67

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

https://developer.mozilla.org/en-US/docs/Web/API/Document/qu... Does the same as the $ query but native in every browser in IE9+ and gives you a native node. Also more performant than getElementBy methods.

document.querySelector(selector) is more typing and more visual clutter on the editor screen.

jQuery is elegant, concise, and was designed by a genius. The "modern" methods are ugly, verbose, and were designed by a committee.

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

#68
post #45

I still use jQuery even for new projects. Yes, these days it's possible to do everything jQuery does using native JS, but I find the native version to be much more verbose and its naming conventions to be far less clear. For example, natively getting a list of children is `el.children` but natively getting the parent is `el.parentNode`, not `el.parent`. Meanwhile, natively getting a list of classes is `el.classList`,…

> For example, natively getting a list of children is `el.children` but natively getting the parent is `el.parentNode`, not `el.parent`.

Actually, .children is the child elements; .childNodes is all the children (including comments and text as well as elements).

> Meanwhile, natively getting a list of classes is `el.classList`, but when I'm getting children I also get a list, so why not `el.childList` instead of `el.children`?

I’m not sure why they want with .classList instead of .classes, but I expect .className is a part of the history. If redesigning it from scratch and still retaining the functionality of .children, I’d rename it .childElements. Certainly not .childList.

And of course, the reasons for most of this stuff is the history. Some of the web’s APIs have aged well; others haven’t.

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

#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')
jQuery does add many extra features but if clean code is the only thing you are after there are other options.

[0] https://www.w3.org/TR/html4/types.html#type-id

Post reply on HN