Why do yo use JavaScript-Libraries like jQuery?

11 points by barnslig ↗ HN
jQuery was released in January 2006. At this time, IE6 was the major browser at the market, so everything concerning to JavaScript was a bit messed-up with Microsoft specific stuff, Firefox market share was growing, the need for animations combined with CSS 2 came up etc. pp.

Today, we have our browsers in a who-is-most-standard-compliant-competition and a lot of nice new APIs with most of the basic ones even supported by IE 8, so most of them have higher backwards-compatibility than jQuery 2.x, which officially only supports IE >9.x.

So I asked me: For which reason are most of the web developers using jQuery? I mean: Selecting DOM elements isn't an argument, Element.querySelector should be faster. AJAX complexibility isn't an argument, ActiveXObject is dead since IE 7. Animations aren't an argument, CSS 3 is grown-up. Since ECMAScript 5, there's Array.prototype.forEach. Events can be easily handled by CustomEvent.

If you're interested in these native APIs called WebAPI, just take a visit to MDN: https://developer.mozilla.org/en-US/docs/Web/API/Element.querySelector https://developer.mozilla.org/en-US/docs/Web/API/element https://developer.mozilla.org/en-US/docs/Web/API/Node https://developer.mozilla.org/en-US/docs/Web/API (Everything at a glance)

16 comments

[ 6.9 ms ] story [ 61.6 ms ] thread
"Selecting DOM elements isn't an argument"

I think this is actually the remaining argument. JQuery was the best at selecting DOM elements and grew from there. I think the question now is whether you find enough value in the other parts of JQuery to include its (rather massive) .js file.

Taking a quick look at the source code directory structure https://github.com/jquery/jquery/tree/master/src, I believe that you could create a minimal, customized build containing only features that you actually want. For example only element selection (which is very convenient and fast IMO) and AJAX.
The biggest reason to use jQuery is the extensive ecosystem. Nearly every JS problem has a jQuery extension-based solution.
jQuery has a lot of useful things, such as a good selector engine (although can be inefficient if you abuse it), lots of easy to hook into plugins, and helpers such as `scrollTop()` & `$(window).on('resize', ...)`. I'm a huge proponent of Angular, but jQuery still has its utility.
there's still no nodeList.prototype.forEach. You can(and should) make it but it's pretty sad qsa was implemented without fixing the most basic thing about its result.

Also jquery neatly abstracts single/ multiple element operations making for shorter code.

Use jquery 2, it's tiny and gives you the tenseness without the extra code for all the old stuff.

Or cut a few pixels from the top of a single image and save bandwidth that way.

jQuery still lacks the ability to select for just a single element. That makes it horribly inefficient for id selectors among other single-element cases.
Sure, and if DOM selector performance is a issue, you should consider ditching it.
One word: "Plugins".
Dependencies, unfortunately I am forced to use it, because it's just there in the code used by someone few years ago.

Plugins are not the reason and fortunately it is changing already, because UI/UX feature developers do not want to be jQuery plugin vendors anymore, they want to promote their stuff under their own brand.

You are mistaking jQuery for a querySelectorAll alias, I have no words for how wrong that is.
I'm pretty sure people also test a lot less when using jQuery. It's a convenience thing.
You are underestimating how much work jQuery does for you.
Practically everything I can think of needing on a daily basis has a solution already made and tested in jQuery. Very rarely do I have to reinvent the wheel, be it tablesorting, an AJAX-sourced type-ahead box, or a nicer date widget. That saves time and effort.

Its ubiquity also means that problems are often already solved in it. Every time I've run into a jQuery bug there has been discussion and work-arounds already posted online by people much smarter than myself.