I hate jQuery fan-boys

Have you ever noticed these people? Ask them the most simple JavaScript question and they’ll respond with the answer in jQuery, even if that answer’s a lot more complicated.

I was on a forum and someone asked a question about shortening getElementsByTagName. He wanted to be able to do this:

var myInputs = getID('myid').getTag('input');

The function “getID” was a simple short-cut for document.getElementById but the asker wanted to know how add a method to that function, although didn’t know how to phrase it. Want to see the first response?

$('#myid input');

That is not an answer – that’s not even close! The jQuery solution would create a jQuery object (or an array of jQuery objects, as it happens), document.getElementsByTagName creates a NodeList. To make something approaching the response the original asker was expecting, you’ll need this:

var myInputs = [];
$('#myid input').each(function() {
    myInputs.push(this);
});

That’s not a NodeList, that’s an Array, but they’re close enough – certainly closer than it was. However, of course, there’s one important thing missing from the top of that solution:

<script type="text/javascript" src="path/to/jquery.js"></script>

This is what I mean by a jQuery fan-boy. They don’t think in terms of JavaScript, they think in terms of jQuery and expect everyone else to think the same. The jQuery solution would work and give access to all the jQuery methods, but for such a simple example it’s far too complicated and totally unnecessary. But the thing I really hate about jQuery fan-boys? I can’t tell them that they’re being idiots without looking like the bad guy.

The sad truth is that calling them out won’t help anyone, all I can do is offer a vanilla JavaScript solution and hope that it makes more sense than their one while teaching them something useful in the process. As much as I want to tell these fan-boys that they’re not helping, the very most that I can do is blog about it.

To all you jQuery fan-boys: every time you try to say that the easiest solution is to use jQuery, be aware that you are adding a massive complication to a simple solution; jQuery is not always the best solution and certainly not the only solution. Before you say it is, please ask yourself the following questions:

  • Is jQuery really the best library to use? What about YUI, Prototype, Dojo or any of the other libraries? Is jQuery the fastest or most efficient — and can you prove it?
  • Do you really need the whole of jQuery, or are you just relying on Sizzle? Wouldn’t only loading Sizzle be easier?
  • Is there a vanilla solution to the problem that is faster or more efficient? If so, why is it better to use jQuery?

I truly believe that if you can not answer these questions, you are not a competent coder and should not be offering advice.

One thought on “I hate jQuery fan-boys

  1. I hate that man!

    At work I have been transitioning from AS3 to JS and if I get stuck for more than 2 seconds, my boss looks at me with pity. He forced me to use JQ to simply gain classList functionality in IE9 when I had a perfectly functioning poly fill.

    You will see a difference in the coming years between the JQ kids and the people who actually strive to learn the language. Use JQ if you are lazy or have to support old browsers, at least understand the underlying principles.

Leave a Reply

Your email address will not be published. Required fields are marked *