Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 56 Β· Getting Started

What jQuery Is and When to Use It

Learn what jQuery is, why it was created, what it still solves in version 3, where you will meet it today and how it compares with plain modern JavaScript.

jQuery is a small JavaScript library that makes it easier to find elements on a web page, change them, react to what the user does and talk to a server. Its famous motto is "write less, do more", and for more than a decade that was literally true: one line of jQuery replaced ten lines of code that had to work around the differences between browsers.

This tutorial teaches jQuery 3, the version you will meet on most websites that use the library today. You will learn how it works, but also when it is the right tool and when plain JavaScript is simpler. Understanding both sides makes you more useful: you can maintain the many existing sites that rely on jQuery, and you can decide sensibly whether a new project needs it.

A little history

In the mid-2000s, writing JavaScript for the browser was painful. Internet Explorer, Firefox, Safari and Opera each implemented the DOM and events slightly differently. Selecting elements by CSS selector was not built into browsers, and even a simple Ajax request needed different code for different browsers.

John Resig released jQuery in 2006 to hide those differences behind one friendly API. Its central idea was simple: select some elements with a CSS selector, then do something to all of them.

JavaScript
$("p").addClass("highlight");

That line finds every paragraph and adds a class to each. Before jQuery, you would have looped over the elements yourself and handled browser quirks along the way. The idea spread quickly. Plugins, UI widgets and whole frameworks, including Bootstrap up to version 4 and large parts of WordPress, were built on top of jQuery.

Why jQuery took over the web

CSS selectors Pick elements the way you write CSS.
One API The same code worked in every browser.
Chaining Several actions in a single readable line.
Plugins A huge ecosystem of ready-made widgets.

It solved real problems that browsers had in 2006.

1 / 2

What jQuery still gives you

Modern browsers have caught up on many features, so is there anything left for jQuery to do? A few things, depending on the situation:

  • Compact, readable DOM code. Operating on a whole group of elements at once, called implicit iteration, remains convenient. $(".card").hide() hides every card with no loop.
  • Chaining. You can string actions together: $("#box").addClass("on").text("Ready").fadeIn().
  • Built-in effects. .fadeIn(), .slideToggle() and .animate() come with a queue that keeps animations from fighting each other.
  • A mature plugin ecosystem. Thousands of date pickers, carousels, table sorters and validators exist, and many still run in production.
  • Consistency in old environments. If a project must support very old browsers, jQuery 1.x or 2.x is still the practical way.

None of these is a reason to add jQuery to a brand new project that already uses a modern framework. They are reasons it remains in a lot of working code.

Where you will meet jQuery today

You are most likely to meet jQuery in one of these places:

  • Existing websites. Millions of sites were built when jQuery was the default, and rewriting working code is rarely a priority.
  • WordPress. Core, many themes and a large share of plugins use jQuery, so theme and plugin work often involves it.
  • Bootstrap 4 and older UI kits. Their interactive components, such as dropdowns and modals, needed jQuery. Bootstrap 5 dropped that requirement.
  • Admin dashboards and internal tools, which tend to live for years without being rewritten.
  • Job maintenance tasks. Fixing a bug or adding a small feature to a legacy page is a typical day for many developers.

Learning jQuery does not replace learning JavaScript. jQuery is written in JavaScript, and you will constantly use ordinary language features such as functions, objects and callbacks. If those are new to you, start with JavaScript functions and the DOM lesson first.

jQuery and plain JavaScript side by side

The best way to judge jQuery is to look at the same task written both ways. Run this example, which adds a class to every item and then listens for clicks, once with each style:

The same task, two styles

Both lists behave the same. The jQuery version is a little shorter, but the plain version is not much longer, and it needs no extra file. For this simple task, plain JavaScript is a perfectly good choice. jQuery pays off when you do many such operations, use its effects or Ajax helpers, or work in a codebase that already contains it.

Full build or slim build

jQuery 3 comes in two flavors, both available from CDNs and package managers:

File Contains Typical use
jquery.min.js The complete library Most pages, and everything in this tutorial
jquery.slim.min.js The library without the Ajax and effects modules Pages that only select, traverse and manipulate elements

The slim build is smaller to download. Because it omits $.ajax(), .load(), .fadeIn(), .animate() and similar methods, calling one of them throws an error. Choose the full build while you learn, and consider the slim one for production only after checking you do not use those features.

What the slim build leaves out

The output shows that DOM methods such as .addClass() are present while .fadeIn() and $.ajax() are missing from the slim file.

Drawbacks of jQuery

jQuery solved real problems, but it has a price, and you should know it before you add it to a page.

  • File size. The full minified build is about 87 KB (roughly 30 KB gzipped). That is small for a library, but large for a page that only toggles a menu. Every visitor downloads and parses it before your code can run.
  • Duplicated features. Browsers now do natively what jQuery was created for: querySelectorAll, classList, fetch, addEventListener with delegation, Element.animate and CSS transitions. A new feature that jQuery offers is often one line of plain JavaScript.
  • Performance overhead. Every $() call builds a wrapper object. In tight loops (thousands of elements per frame) the wrapper cost shows up, and chains such as $(".row").addClass("a").css(...) touch the DOM more times than a single plain-JavaScript pass.
  • Slow, forgiving selectors. jQuery silently accepts an empty selection, so a typo in a selector does nothing instead of failing. That makes bugs easy to miss, and non-CSS selectors such as :visible cannot use the browser's fast selector engine.
  • A second way to do everything. Teams that mix jQuery and plain DOM code end up with two styles in one codebase. Mixing jQuery with React, Vue or Angular is worse, because both want to own the DOM.
  • Plugin quality varies. Many plugins are old, unmaintained, or depend on a specific jQuery version. Upgrading jQuery can break them (see what changed in jQuery 3).
  • Weak fit for modern tooling. Component frameworks, bundlers with tree shaking and TypeScript work better with small, focused modules than with one global $ that hangs everything on a single object.

None of these make jQuery wrong for an existing site. They are the reasons new projects usually start without it.

Should you use jQuery in a new project?

A sensible rule of thumb:

  • Maintaining a jQuery site: yes, use what is there, and learn it well.
  • Small page, one or two interactions: plain JavaScript is usually enough.
  • Using React, Vue or Angular: do not mix jQuery in; those frameworks own the DOM, and direct manipulation causes confusing bugs.
  • Need a specific jQuery plugin: then jQuery is a dependency you accept along with it.

Later in this course you will see side-by-side recipes in From jQuery to Modern JavaScript, so you can move code in either direction with confidence.

Check your understanding

Quick check Β· 4 questions

of 4 answered You scored / 4 Β· perfect!

  1. 1. What problem did jQuery mainly set out to solve?

    jQuery's value was a single, consistent way to select elements, handle events and make requests, regardless of which browser ran the code.
  2. 2. What does "implicit iteration" mean in jQuery?

    $(".card").hide() hides every matching card. You do not write the loop yourself.
  3. 3. Which jQuery file leaves out Ajax and effects?

    The slim build omits the Ajax and effects modules, so it is smaller but cannot call $.ajax() or .fadeIn().
  4. 4. You are building a new React application. What is the best advice about jQuery?

    Frameworks keep their own view of the DOM. Changing nodes behind their back with jQuery leads to hard-to-find bugs.

Summary

  • jQuery is a JavaScript library that selects elements and acts on them with a short, chainable API.
  • It was created in 2006 to smooth over browser differences; many of those differences have since disappeared.
  • It is still common in WordPress, Bootstrap 4 and legacy sites, so knowing it is a practical skill.
  • Plain JavaScript can do most of what jQuery does, but jQuery stays convenient for effects, plugins and concise DOM code.
  • The full build includes Ajax and effects; the slim build leaves them out.

Next, let's set up jQuery and write your first script.