Jamie Balfour

Welcome to my personal website.

Find out more about me, my personal projects, reviews, courses and much more here.

Part 2.2Why use jQuery?

Part 2.2Why use jQuery?

As with all libraries on the web, there is a slight performance hit for adding more and more code to a site. Therefore, the benefits to adding a library such as jQuery need to outweight the disadvantages for it to be worthwhile.

Speed and efficiency

First of all, jQuery is a powerful wrapper to many functions and methods built-in to vanila JavaScript. On occasion, jQuery makes writing the equivelant JavaScript considerably more condensed. For example, when selecting elements:

var elements = $("p");

In pure JavaScript the same code could be represented as:

var elements = document.querySelectorAll("p");
//It could also be represented by:
var elements = document.getElementsByTagName("p");

Of course, this is a minor saving at present because it's only used the one time. However, if it's used over and over again this can save some real time and effort. In terms of downloads, this is great. In terms of saving the developer time, this is much, much easier to remember.

Everything in jQuery is written in pure JavaScript. This means it is possible to write everything that jQuery does in a JavaScript method, but then of course, why reinvent the wheel? jQuery is readily available and it's possible to select only the parts that are needed rather than the whole library.


Perhaps the main benefit of jQuery is that of cross-platform. jQuery aims to be platform independent and manages to include solutions that support different browsers. By example, Internet Explorer 8 has different methods for binding an event to a handler than those of Google Chrome. jQuery has just one implementation that wraps over both of these implementations so that code is not repeated for each browser. This is but one example of how jQuery deals with cross-platform development like this.

Feedback 👍
Comments are sent via email to me.