Learning jQuery

Learning jQuery

If you’re learning JavaScript and Web development, you might be wondering whether to learn jQuery. After nearly a decade of existence, jQuery has grown into a fundamental part of JavaScript coding in Web development. First, let’s look at why jQuery came to be, and whether it’s still necessary. Then we’ll wrap it up with some conclusions on whether you should learn it.

Check out the latest JavaScript jobs.

In the early days of Web development, there were some problems that made coding difficult. First, there was very little compatibility between browsers. Microsoft went off in one direction, and other browser manufacturers went in others. In order to write code that could be called in response to a button click, you had to write several versions for different browsers. That was the first problem.

The second problem was there weren’t any efficient ways to “drill down” into your HTML elements. Say you had an element containing other elements, with those elements containing other elements. To access these elements from JavaScript, you pretty much had to give a unique identifier to each element. What developers needed was a uniform way to assign event code to elements, and a uniform way to access the elements.

Several people attempted to create libraries to help simplify the coding. Of these, a couple quickly rose ahead of the others, and of those, one—jQuery—really took off. Within a few years, jQuery became an essential part of writing Web applications. It was so essential that many of us wished some of the jQuery features were built right into the JavaScript implementations in the browsers.

As browser standards evolved, and as Web developers put pressure on Microsoft to conform to standards, the browsers gradually came together. By the time IE9 was released, browsers were pretty well uniform in how they handled events and accessing elements. We were getting closer to being able to write one piece of JavaScript code and have it run on all the major browsers without modification. (We’re technically still not there, but we’re much closer than we had been.) This meant that writing event code was much easier.

Additionally, the Web standards group (W3C) took note of the way jQuery allows you to drill down into your elements, using a method that essentially matches CSS’s way of naming elements. As such, they added some standard methods for accessing your elements using these same CSS selectors.

And now we’re at a point where many of the missing pieces (and additional features) jQuery filled in are present in browsers. So do you need to learn jQuery anymore?

Let’s look to some of the experts to get their take.

In this article over on SitePoint, Craig Buckler makes the argument that jQuery is just an abstraction. Indeed, he’s correct; jQuery is really just JavaScript code that simplifies your day. Anything you do with jQuery, you can still do without jQuery. And over on another blog, Web development guru Todd Motto presents a line-by-line comparison between jQuery calls and native calls, showing that it’s almost as easy these days just to use native calls.

For example, Motto provides this code in jQuery:

var i = $(“.myclass”);

This searches for all elements on the page that have class name myclass. Now here’s a bit of code without jQuery:

var i = document.querySelectorAll(“.myclass”);

This does the same thing, using a function (querySelectorAll) that’s built into the newer browsers.

If you dig further, you’ll find the same conclusion on other blogs: People are realizing they don’t necessarily need jQuery. Indeed, in my own development work, I’ve noticed over the past year that I’m relying on jQuery less and less.

But before we move on, let’s look at jQuery’s official blog. Here, we see that the jQuery developers have stripped out the code needed for older browsers, resulting in a separate version of jQuery that targets only modern browsers. Because it doesn’t need nearly as much browser-specific code, this modern jQuery library is much smaller in code size than previous versions. To me, that sounds like even more of a justification to abandon jQuery, even if the platform’s developers don’t want us to stop using it.

While a lot of people might argue that we don’t need to learn jQuery, there’s still one big reason for doing so: Legacy code. If you’re going to go to work at a company that already has JavaScript browser code, there’s a strong possibility it has jQuery throughout its code. There’s also a matter of preference: With jQuery, my code is tighter; individual lines of code are shorter. People still like jQuery and its elegance, and they’re going to continue using it, even though they might not have to.

If you’re just starting out in Web development, my suggestion is to learn both jQuery as well as JavaScript’s new, native ways of accomplishing the same tasks. Then decide for yourself if you need jQuery.