203

How many JavaScript questions can be answered with "use jQuery"?

Looking at JavaScript questions, all too often the answer seems to be "use jQuery," sometimes in as few words. We can end up with answers which feel more like plugs getting the asker to try jQuery (the Silver Bullet) than a concise solution to their question.

Mind you, jQuery is dope (some might even say "sick" or "dyn-O-MITE!") and as such, "use jQuery" can be an effective solution to 9 out of 10 JavaScript problems.

But I feel strongly that it's not enough —as a web developer— to know jQuery and not understanding the underlying JavaScript.

For example: A project I was on had a nifty widget to configure a webpage, which made use of jQuery. When the search solution was integrated, however, it turned out that somehow the search solution conflicted (rather seriously) with jQuery and broke the widget. When faced with doing without the (expensive) search solution (which had been paid for) or the (free) jQuery library, the decision makers tasked me with refactoring the widget to work without jQuery. Obviously I couldn't have done it had my knowledge not gone "use jQuery."

Bearing all these in mind, at what point is "use jQuery" not an appropriate answer to a JavaScript question?

20
  • 222
    I see you're trying to determine when to use jQuery by analyzing the problem at hand and applying logic and reason to make an informed decision about its possible implementation. You should totally drop that and try jQuery.
    – snicker
    Commented Apr 1, 2010 at 21:28
  • 94
    @snicker I see you're trying to convince someone to use jQuery. You should totally drop that and try jQuery.
    – Earlz
    Commented Apr 28, 2010 at 23:43
  • 37
    Isn't jQuery passée now? I thought everyone was using the new EczemaScript. It's bundled with every browser and is, like, good for your skin too.
    – Dan Diplo
    Commented Apr 29, 2010 at 8:40
  • 6
    You have to love the "I'd like to add two numbers together in JavaScript - Why, simply use jQuery..." style questions, if only for the "when all you have is a hammer, everything looks like a nail" syndrome. :-) Commented Jan 21, 2011 at 13:27
  • 5
  • 7
    I agree completely. jQuery is great, but it seems like people lean on it a little too much now-a-days, without having a solid enough understanding of JavaScript. Take the crutch away, and many are left crippled. Commented Oct 3, 2011 at 16:49
  • You might want to take a look at this question: stackoverflow.com/questions/471597/is-jquery-always-the-answer.
    – Kibbee
    Commented Oct 3, 2011 at 19:26
  • 7
    Good luck getting jQuery to run on Node. JavaScript isn't just for browsers. Commented Jan 24, 2013 at 9:13
  • 19
    I'd like to see a without-jquery :-) Commented Jan 18, 2014 at 3:21
  • 4
    Well JQuery has a special plugin called javascript, you can use it to make more JQuery plugins, and that's all for it... basically a question tagged javascript and not jquery should answer javascript (although it might also provide a hint to Jquery, it is in fact like a question in assembly language and a answer in a higher language)
    – yoel halb
    Commented Jan 31, 2014 at 1:47
  • 6
    When your writing JavaScript for IE3 because your stuck in a special kind of legacy hell only known to you and 3 others who have a token ring network with you. Commented Feb 4, 2014 at 16:52
  • 1
    I think this question is relevant beyond just SO, there are many SE sites dealing with both Javascript and jQuery. Commented Apr 21, 2014 at 23:03
  • 1
    Every time I see a useless-use-of-jQuery, I get a strong urge to vote to migrate the question to Super User. Does that count? Why do so many people feel the need to source 84kb or more of external libraries just to fire a function on document ready? Blows my mind.
    – rojo
    Commented Nov 24, 2014 at 14:12
  • 2
    Yes, we do, @Shadow. More importantly, this is fairly heavily referenced - I'd have a whole chain of additional posts to migrate if I moved this one. It's doing no harm here; moving it can wait until we get cross-site auto-crosslinking.
    – Shog9
    Commented Dec 30, 2014 at 17:15
  • 3
    Quoting from the link I gave you... "Please don't close questions just because they happen to have been written in the context of Stack Overflow. If they are truly only relevant to SO and no other site, then fine, close. But if you're not sure, go find something else to do."
    – Shog9
    Commented Dec 30, 2014 at 17:18

15 Answers 15

222

Pretty much never.

For convenience, here's the image the above link points to:

spoof screenshot with a high-scoring jQuery answer and a downvoted legitimate answer

Given the URL and text in the image, I suspect this image was put together by our old regexinating pal bobince!

9
  • 11
    Link to his post: doxdesk.com/updates/2009.html#u20091116-zalgo Commented Apr 29, 2010 at 0:35
  • 31
    This is obviously misleading. The proper use of a + operator would be to sum the values of the values of two text boxes. Like so : var c =$("#a").val() + $("#b").val(); alert(c);
    – user146643
    Commented Apr 29, 2010 at 18:25
  • 1
    we have a possible contender!! stackoverflow.com/questions/11907653/…
    – bPratik
    Commented Aug 10, 2012 at 19:03
  • 2
    I'm just wondering, which library OP finally have chosen for the job ; ).
    – Teemu
    Commented Apr 5, 2014 at 19:29
  • 1
    Here's the new (and legitimate) version Commented Nov 4, 2014 at 16:15
  • 3
    Did you guys see the new beta version of StackExchange running purely on jQuery? There's just a question box (users can't give answers), because all the answers are provided directly by jQuery! Can't wait for it to become a standard.
    – Shomz
    Commented Dec 25, 2014 at 14:04
  • 1
    @user146643 That's incorrect, alert is part of the standard DOM, you should use a jQuery equivalent.
    – mystery
    Commented Dec 27, 2014 at 16:34
  • You can just link to this post instead
    – royhowie
    Commented Jul 21, 2015 at 6:26
  • 2
    The answer to the question "… at what point is "use jQuery" not an appropriate answer to a JavaScript question?" is ALWAYS, not "never".
    – RobG
    Commented Jan 23, 2018 at 5:19
75

When any of the following is true:

  • It is the entire answer, with no explanation of exactly how jQuery helps
  • When the problem can be solved simply without jQuery
  • When the question specifically asks for no javascript frameworks
  • When the question is tagged or mentions a competing framework
  • When someone else already posted it
45

JavaScript !== JQuery

JQuery is largely a replacement for the DOM. It provides a lot of tools for working with browser specific stuff, not JavaScript specific.

There's questions about JavaScript itself that can't be answered with "use JQuery". Questions about scope, the way functions work, objects, etc.

However, JQuery can be used beyond questions about JavaScript or the DOM. Just the other day a waitress asked "What would you like?" at a restaurant to which I replied "just use JQuery". She knew precisely what I wanted at that point

5
  • 27
    Don't you mean !==? ;)
    – Skilldrick
    Commented Sep 28, 2010 at 10:46
  • 13
    @Skilldrick Gosh, this is old by now, but I originally had !== until someone edited it. They probably weren't used to JavaScript?
    – Bob
    Commented Nov 1, 2011 at 0:46
  • 14
    @Bob: jQuery is largely a replacement for the DOM...? The wording could possibly cause someone to miss-interpret jQuery. jQuery does not replace the DOM but provides an API which simplifies the interaction with; and the manipulation of the DOM, makes Ajax calls easier and includes many other features, while working across multiple browsers. The one thing it does not do is replace the actual DOM.
    – Nope
    Commented Apr 9, 2013 at 20:33
  • 14
    Don't you mean !$(JQuery).is(JavaScript)
    – Adria
    Commented Jan 30, 2015 at 16:13
  • I've used JQuery from VBScript.
    – Zev Spitz
    Commented Sep 26, 2016 at 18:17
38

When you're trying to reboot the system to get the electric fences back on.

3
  • 51
    Seriously, even jQuery knows better than to shutdown the raptor fences.
    – Craig
    Commented Apr 29, 2010 at 4:22
  • 5
    The reason I ask is that I'm told large javascript libraries, such as jQuery and protocol aren't born man-eaters. Is that true? These libraries must learn somewhere along the way that human beings are easy to kill. Only afterward do they become man-killers. So I wonder: have they learned, somewhere along the line, that human beings are easy to kill? Commented May 21, 2010 at 19:05
  • I heard $.setRaptorFences(":on") will be supported in the next version.
    – Roy Tinker
    Commented Feb 5, 2018 at 22:52
33

So my question is - bearing all these in mind - at what point is "use jQuery" not an appropriate answer to a javascript question?

A question which is not answerable with "Use jQuery" is not an appropriate question.

My answer is correct because my answer is correct.

3
  • 2
    Boy am I happy my boss left early, cause I am dying right now.
    – Jeff
    Commented Sep 18, 2012 at 14:09
  • 11
    @Jeff are you alive? did your boss come back? it's been 2 years, and no word... did jQuery become the man-killer as the OP commented?
    – kumarharsh
    Commented Feb 18, 2015 at 13:30
  • 4
    @kumar_harsh *contemplating on not replying to keep the illusion alive*
    – Jeff
    Commented Feb 18, 2015 at 13:36
20
$("answer").append("use jQuery when:always")
17

It's unbelievable how people think about JavaScript and jQuery -- or how they don't think about JavaScript.

Particularly, I don't like jQuery and I would rarely recommend it to someone. jQuery has cool features and a bunch of plug-ins, but its philosophies make people answer questions like the above.

I like to write scripts in which I know exactly what I am doing, so I have total control over it. With jQuery/jQuery plug-ins, you usually -- not aways, of course -- write something that you at most have just a clue about what that does under the hoods. The reason? Philosophies. What about some customization? I'm tired of people coming to me asking how they customize the way that jQuery/jQuery plug-ins do stuff. My answer: "learn JavaScript".

5
  • 7
    Eh... Those who know JavaScript can read through the jQuery source fairly quickly. Those who don't still could, but probably won't because they want a magic box. See also: stackoverflow.com/questions/215589/…
    – Shog9
    Commented Jul 20, 2010 at 5:06
  • 1
    @Shog9 that's assuming they want to and have the time
    – Michael
    Commented Jan 30, 2015 at 17:27
  • 1
    If you don't want or have time to learn, then there's a limit to what any answer can do for you.
    – Shog9
    Commented Jan 30, 2015 at 17:29
  • @Shog9 I've the time to do useful work, NOT to wade through thousands of lines of code someone else wrote and probably didn't document to figure out what something does.
    – jwenting
    Commented Sep 28, 2016 at 11:41
  • 1
    You work alone then, @jwenting? Good for you. But if you had reason to learn something about jQuery, it's quite well-documented and clearly written.
    – Shog9
    Commented Sep 28, 2016 at 14:47
14

Probably when the answer "use jQuery" itself doesn't solve the question or problem at hand? At the end of the day jQuery itself is a framework solution that still requires some implementation details to really solve a problem.

If the op were to ask:

What JavaScript framework should I use for accordions and date pickers?

A valid answer may be:

You should take a look at jQuery and jQuery UI to handle this.

Outside of that... "use jQuery" doesn't really solve anything...

2
  • 16
    I see you are still fighting about "use qQuery" answers by replying to your own question.You should totally drop that and try jQuery. Commented Apr 2, 2010 at 0:59
  • 18
    "use jQuery"; should just be part of ES Harmony like "use strict"; Commented Jan 6, 2012 at 0:39
7

In my opinion, "use jQuery" is not a valid answer any time the asker has not specifically asked about jQuery, and here's why. The user should have to opt-in to hearing about jQuery, not opt out.

Google is a great tool. Anybody interested in finding about about javascript libraries can easily do so, and there are a lot of great ones out there. But directing every question about how to do something into an answer about how to do it in your favorite library is redirecting what could be a good, general purpose answer that anybody could use, into one that is only useful by people who are able to use your library. Rampant evangelism notwithstanding, there are a lot of projects in which using jQuery is outside the scope and requirements of the project. The project might require using a different library or no library at all, and the library chosen if any might not factor into the wording of the problem. The user might simply be interested in knowing how to do it in plain javascript due to the fact that certain things are really hard or impossible to do properly unless you know what browser or even version of the browser or OS you are using. jQuery might abstract this away from you, but in certain cases this is undesirable, and I would argue it helps keep programmers complacent when they should be rising up and calling for better interoperability between browsers.

It seems like 90% of the time I am trying to find out how to do something in Javascript all the answers I find are how to do it in jQuery. As a result, I either have to dig into the jQuery source code (not gonna happen, I've tried it, and I just don't have the time) or ask my own question specifically requesting how to do it in plain javascript. Now I have wasted my time and everybody else's repeating a question that was already answered, but in such a way that it is not useful to me.

Having said that, if you feel the need to tell the user about jQuery, I have no problem with you supplementing your answer of how to do it in Javascript with how to do that in jQuery. Now you have not only educated the user how to do what they wanted in plain Javascript, but you have also shown them how much easier it is in jQuery, and they can make a more informed decision as to whether they want to start using it.

1
  • 5
    Solution: Rename jQuery to jAardvark. Stackexchange sorts labels alphabetically. Google weighs the first title word extremely heavily. Therefore all jQuery questions rank too high for JavaScript.
    – Adria
    Commented Jan 30, 2015 at 16:09
6

Use MooTools or Dojo.

There, I said it.

3
  • 57
    I think you ment "Use jQuery", typo perhaps?
    – pasuna
    Commented Mar 8, 2011 at 12:24
  • 4
    @saturation Common mistake. Commented Aug 23, 2015 at 5:45
  • 5
    @pasuna the keys are like right next to each other.
    – jjrv
    Commented Mar 4, 2017 at 21:38
6

The only question to which the answer is not jQuery is "To what question is jQuery not an answer?"

Presto! Recursion.

1
  • 4
    You can use jQuery to find the answers though.
    – user64742
    Commented Jul 3, 2017 at 17:37
6

Yes, it saves loads of time and frustration. jQuery is great. I love jQuery. But here's personal experiences where I won't want "Use jQuery" as an answer:

  1. When I'm using Greasemonkey, jQuery doesn't work without an ugly workaround. Usually I don't want to bother.

  2. If a client's site already has another JS library in play (read: Prototype / Scriptaculous), running jQuery.noConflict() in tandem is a last resort; I've tried it before and all it causes is problems and confusion:

    So, this $ belongs to jQuery? No wait, Prototype. So why is all the Prototype stuff broken if jQuery's in noConflict mode? Why is Firebug reporting that $ is the jQuery object? Ok, now I have Prototype working, but some of the jQuery plugins are screwing up. [string of expletives from frustration]

    I've learned that the appropriate solution is to Google prototype [whatever I'm trying to do] example and I get by just fine. If that ever fails, I'll ask on StackOverflow.

  3. By the same token, when I'm freelancing on a client's web site, if the client is requesting animations and AJAX calls on a page, I'm going to use jQuery. But I'm not going to add the entire jQuery library to his page's overhead when all I need is document.getElementById("foo").

Don't get me wrong. I'm a huge supporter of jQuery. I author plugins, for God's sake. It's just that jQuery is only a subset of JavaScript. It's usually a great option, but not always the best option.

1
  • 2
    to solve that greasemonkey problem... use jquery.
    – user64742
    Commented Jul 3, 2017 at 17:37
6

"Use jQuery" is not a valid answer to any javascript question starting "I was hacking on the internals of jQuery, and ..."

1
  • 2
    What, jQuery isn't a valid solution for its own source code? Nonsense, it's jQuery all the way down.
    – Roy Tinker
    Commented Feb 5, 2018 at 22:55
0

Obviously simply saying "use jQuery" doesn't solve anything it's self. But as a framework/library jQuery is designed to solve, or make simple, many common JavaScript problems. That's why people find it so useful and why the answer to so many of the JavaScript questions posted boil down to "use jQuery".

That being said it's not a replacement for understanding the JavaScript underneath.

There are places where jQuery has a bug, or you're trying to do something that isn't within the scope of jQuery, jQuery UI or any of the jQuery plugins then you're obviously going to need to write your own JavaScript. There are also things where for performance issues you won't want to use jQuery.

So really it depends on what the question is, but for the most common questions "use jQuery" is the answer, and that's kind of the point.

0

Any answer suggesting jQuery should still include the answer of the question using jQuery.

But in general, I hate answers that raise more questions. And the question is: why jQuery and not YUI.

...and when you write a Chrome-extension, did you know that it even has XPath?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .