What is jQuery?
jQuery is a JavaScript library designed to simplify front end web development. It is the most widely deployed JavaScript library by an insanely large margin.
Why use jQuery
There are quite a few reasons you’d want to use jQuery, or a library like it, in your project rather than vanilla JavaScript. Here are a few examples.
Ease of use
JavaScript can be a handful, jQuery can be far cleaner and more concise than the equivalent in vanilla JavaScript. Take a look at these two examples of a fade in effect:
JavaScript Fade In
function fadeIn(element) {
element.style.opacity = 0;
var last = +new Date();
var tick = function() {
element.style.opacity = +element.style.opacity + (new Date() - last) / 400;
last = +new Date();
if (+element.style.opacity < 1) {
(window.requestAnimationFrame &&
requestAnimationFrame(tick)) || setTimeout(tick, 16);
}
};
tick();
}
fadeIn(element);
jQuery Fade In
$(element).fadeIn();
Cross browser support
Cross-browser support is one of the most difficult things about web development. jQuery normalises this so you don’t have to worry about different browsers as much.
This reason becomes less true with time. However, If you need to support older browsers, particularly anything older than IE8 then you should seriously consider jQuery.
Lots of people use jQuery
It might seem like a silly reason to use something just because loads of others are using it too. Having said that there are some real benefits to that thinking. In particular, there are plenty of resources available to help you learn and use jQuery. So if you need examples of how to do something you should have no problem finding them.
Even if you’re already a skilled developer, the practice of coding is continuous learning. So it’s always good to have a strong community around the area in which you work.
Why not use jQuery?
Based on the above you’d think jQuery would be a no brainer, and in many situations that’s true. However there are plenty of situations where it isn’t the best option, here’s why.
You can do everything without it
There is nothing in jQuery you can’t do in vanilla JavaScript. So depending on your project adding jQuery to the mix may actually be creating an unnecessary dependency. If you’re not using many of jQuery’s capabilities in your app, it pay’s to consider alternatives.
jQuery contains hundreds of methods that on many applications you’ll never use. There’s no sense in bundling all that in if you’re only using a small part of it.
People are moving away from jQuery
This one is a little contentious depending on who you’re talking to. For a few years now there are signs that people may or may not be moving away from jQuery. Regardless, if new