Why do people use jquery




















I can't imagine living without jQuery, but I use it for content scripts in browser extensions. I see no reason to use it for web development and never did. In content scripts I use it mainly to undo the nefarious work of others; to reverse engineer deliberately convoluted class name schemata, for example. I haven't used jQuery in ages.

For the few times where the JavaScript is cumbersome I write quick wrappers. New projects should be using modern javascript frameworks. Thank you! I really appreciate the feedback. You made some very good points about loading time, and jQuery is definitely not worth it. WordPress depends heavily on it too. I work primarily with WordPress, so I can't seem to escape. If size matters for you so badly, you should avoid React in the first place.

And jQuery only 27kb gzipped. Depends upon the case use. If I am using some jquery plugins then jquery is needed. Mostly in my personal projects I tend to use it as a last resort.

If your site requires indexing by search engines SPA is not a solution. Old style multiple pages website featured by jQuery will do much better. In a strange way Jquery can sometimes reduce code as well It is almost half the size I mean it would take a lot of code IIRC its 90kb, but if you have a huge single page project in the long run you could end up saving.

Jquery covers a lot of things and a lot of backward compatibilities. If they went through it and removed all the backwards compatibility bs they could probably shop it down to 40kb easily. For example I wrote my own mini jquery clone.

It only has a few things, but they are what I used jquery for the most. I've also seen a pretty big project where they just dedicated a shorthand for 'document. I guess I rarely use libraries if I don't have to. If it is something small there is no point and if it is really big then you are probably using something else view, react or whatever. Dolamu Asipa - Nov 8.

Darragh O'Riordan - Oct Calin Baenen - Oct DEV Community is a community of , amazing developers We're a place where coders share, stay up-to-date and grow their careers. Create account Log in.

Twitter Facebook Github Instagram Twitch. Why is jQuery so popular? Cross-browser compatibility: JQuery provides an API that can work on most browsers, something that's very hard to achieve if you're using javascript, this saved developers a lot of problems. Is it still worth learning in ? The short answer is no , here's why: Better alternatives: Javascript has matured so much during these last years, it supports a lot of new APIs and its community has built so many great libraries to fill any void jQuery might leave.

Upload image. Submit Preview Dismiss. Dropdown menu Copy link Hide. We like to be part of the discussion over here at Dev. Mouad K. It's a dependency - yeah, 30k or so.

Some javascript-library variant of the Total Perspective Vortex may be warranted to try to make sense of this. A more interactive as in, between server and browser , more stateful integrated model?

Oh, yeah, totally, I can see that, but that 'formula' surely isn't the go-to strategy for every web page out there, right? Most of the pages I write work perfectly well via a 'server generates data, server throws it through a template and sends it to browser, client downloads jquery and some javascript for that page which adds interactive elements', and wouldn't be any 'nicer' if it was a much more javascript-native fully state-shared amalgamation.

When I do need that live-updating stateful interaction model, sure, don't need jQuery. But that 30k is the least of my worries if that happens. It's not that simple. It used to have a more capable renderer, they rolled it back to the Word one no animated GIFs! So Outlook is really crappy, versions before and after that, a bit less so. The lovely world of enterprise software. Your use of the word "still" is a little misleading. My theory is still that it was about using Word as a component to write replies.

Outlook is part of Office; Word is part of Office. IE, and now Edge, is a different business unit. Not inexplicable at all. NIH doesn't only apply at corporate boundaries.

Good code management can solve this, like using a class or class like construct e. But jQuery misses a lot of features to be a truly component based solution. One of the most common things in JS is to attach listeners to HTML elements, however the most common way when doing so in jQuery is that you have a bunch of selectors and then some listener code, but that type of statements is not self explanatory, you have no function name to describe what it is doing or any other context.

You see all these registrations of event listeners scattered across the project. What do they do? Are they in use? Hard to tell because searching your source code for a CSS selector is very difficult. That is why jQuery based projects usually have tons of leftover code from the last refactor, no one dares to touch it. Many component based libraries out there lets you register a method name on the HTML element directly.

Much better. It is true that you can add event listeners inline on your HTML element, but that is not how jQeury is usually written, because it is selector based. I think a lot! When you just want to add a small bit of interaction to a mostly-static site, jQuery can help. There's a current trend to complicate things with a JAM stack that really don't need to be complicated.

Server side rendering is way easier to do and is often faster to load for the client. SPA make sense whenever you want to write a proper application running in the browser. When you just want a website, stop the SPA madness. For very small amounts, perhaps, but honestly, even then I think it has limitations. As an anecdote, about six months ago, I needed to add a couple of dynamic forms to a static site.

I wrote the first one in jQuery site was already using it due to the theming , and making sure handled all the various edge cases, and fixing one bug didn't cause another was far harder and time consuming than it should be. Out of frustration, I wrote the other form in VueJS, and hacked the whole form in about an hour or two. My take away was that anything involving state in jQuery can get overly complicated very quickly.

Jquery has been around for 14 years. That framework.. You want to be as confident as possible you can bump to a new version on your old site in 4 years if you have to? Use Jquery. SamuelAdams 8 months ago root parent next [—]. Plus it's easier to hire for. Or just fork Alpine and fix it. Perhaps even htmx? This looks very cool, thanks. To be fair the first case is only static for the initial load then becomes a single page application.

Yeah, but very few sites need to be SPAs. SPAs come with a tremendous amount of extra requirements that, over time, can mire projects in cruft. There's no need to complicate static sites with jQuery. All it does can be achieved with vanilla. Vanilla has always been able to do what jQuery can, otherwise jQuery wouldn't exist.

It all depends on what your threshold for abstraction and verbosity is. That is going to depend on what you are doing and who you are. I mean, all you really need is a Turing Machine, but they're not very pleasant to program. Same thing with vanilla JS and jQuery. Well, yes. Every JS library can be written in vanilla JS. The point of jQuery, React, etc.

I tend to agree, and unless you have to support like IE prior to IE9 it will probably easily support all of your target browsers. WhyCause 8 months ago root parent next [—]. Promises aren't available in IE11, and as the last "true" IE, I imagine it'll be around a bit longer than it should be. I recently had to rewrite a bunch of vanilla promise-based code to use jQuery promises once I realized IE11 didn't work. As a competitive code golfer, I can confidently say that vanilla JS has never offered the raw performance of jQuery.

Have you actually compared the two methods in a real website? It's like saying why use Ruby when you can use Java. The Javascript document API is super verbose. No thanks. Kaze 8 months ago parent next [—]. Conversely, looking at how you do it through jQuery after seeing how it is in Javascript gives me the same reaction. The fact that jQuery is usually assigned to the dollar sign definitely doesn't help, especially for beginners. The amount of questions I've answered that stemmed from a fundamental misunderstanding of how Javascript works, all because they learned jQuery instead of Javascript, is pretty significant.

When I learned that it was simply a function invocation that returned a jQuery object so you could chain it, I was absolutely shocked about the simplicity of that statement. Beginning developers sure like to project their cognitive insecurities onto programming. Or at least, I did :. There's so much magic in programming that as a beginner, it's hard to know which magic you should dig deeper into, vs which is such a treacherous rabbit hole you're better off cargo culting.

It think this is true of many technical things. Statistics, sailing, car mechanics, photography What I love about HN is it often gives clues as to which are the interesting rabbit holes. That argument stands true for most frameworks on most platforms. I prefer the dollar sign; it's pervasive and concise.

Kaze 8 months ago root parent next [—]. I disagree. There's nothing about React, Vue or any other framework that I'm aware of that does anything similar to jQuery's dollar sign. The only magically-looking abstraction I can think of is JSX, and that's not only not mandatory but very obviously something that's off the curve.

Unlike the dollar sign, which just looks like a special construct of the language. Xevi 8 months ago root parent next [—]. Svelte uses the dollar sign. Wow, that looks weird. Thank you, I hadn't heard of Svelte before. No one blames you for not knowing about the th javascript framework. You don't have to use all of it though, right? Easily memorized with practice IMHO. Also they are all extremely well documented on MDN. Technically that breaks, you want: document.

Yeah, oh so many years ago I realized that I use just a small subset of jQuery, and just rewrote those bits, to avoid having to inject whole of jQuery into all pages that I browse I had some global https? You should totally open-source that, put it on NPM, and write an article or so about it. Everyone will have different set of methods they use.

Point of this is that if you need some method you can just add it in in lines or remove one you don't need. So it's not the best fit for NPM. BTW, NodeList. Your example does not work.

You need to iterate over that array. And that's exactly why jQuery is so much more convenient over native API: you can just treat collections of elements like an element and jQuery will iterate for you if necessary. Another jQuery advantage is pseudo-selectors which don't exist in CSS. There are plenty of convenient one-liners in jQuery which will expand to plenty of lines in native API.

Just a nitpick, but querySelectorAll returns a NodeList. This can bite at times, for example IE supports Array. Yeah this gets me every time. You can. I usually end up wrapping it in an array and calling map on it like [ ROARosen 8 months ago root parent next [—]. I think the fact that your very simple example which is already longer and more complicated in your version doesn't work shows the advantage of jQuery. How so? Epskampie 8 months ago root parent next [—].

There's a ton of other functions you need like element. At that point you might as well save yourself and the person after you a major headache and just use jQuery whose API everybody knows. The big magic of jQuery is that you can act on an array of elements as if it were a single element. Your alias does not give you that at all. Good point. I'm still a little bit sad we got fetch as part of javascript when the request module had such a great interface.

I still prefer the look of it. Can't say I've ever heard that as an issue before.. Also I think the main point was there are so many better frameworks that manage the DOM better than jQuery as the need has evolved. I'll always have fond memories of jQuery but I don't see it as my go-to anymore, by a long shot.

It's annoying that it returns a NodeList which doesn't have some common array-y methods and the like. While these aliases are certainly convenient, the jQuery semantics are much nicer and more intuitive IMO. I was trying to be concise in the original response. Yeah, but 19 helper functions later and you've got half of jQuery.

I'd rather use a properly tested library. Using this since ages. Also use window. One could also save document. That would be very confusing for unsuspecting reader. I personally consider that a con, not a pro, and one of my many reasons not to use jQuery. I help teach an introductory programming class to high school students. JS has improved by including methods like like querySelect and.

Since js dom has already reduced alot of complexity with new methods the difference jquery provide for less code is minimal and hence becomes unessary as with any library it increases the page loading time. Honestly , you dont have to make a big deal whether to learn jquery or not , people look at frameworks the wrong way similarly to bootstrap.

The purpose of any library and jquery is to reduce coplexity in code and you decide whether if its worth for your project. Alot of document examples are still written in Jquery , and even if you want to use pure vanilla JS you still need to look at examples and translate jquery to pure JS. I have used jquery and bootstrap for my final year project for example because writing it in pure css and js takes alot of time to write so using a framework make sense.

Regardless you should spend more time in the fundamentals on your own personal projects html,css and js because there are alot of times you have to tweak code and you have to look at the underlying structure of libraries like changing certain css in bootstrap for example.

It quickly becomes hairy when you need to update multiple things at multiple places. Thanks for that image owel that helps put it in perspective. Compare those of course to the relatively modern vanilla js framework. Not to mention,. Fixed the link. Not sure what happened there. Many of the things jQuery offers is easily implemented in vanilla and it works significantly faster.

Why does everyone hate on JQuery?



0コメント

  • 1000 / 1000