jQuery is an open-source JavaScript library that wraps common browser tasks, such as selecting elements, handling events, animating content and sending Ajax requests, in a concise, chainable API built around the $ function. Released in 2006, it became the most widely deployed library in browser JavaScript because it hid inconsistencies between browsers behind a single interface.
On the Web today, jQuery is no longer necessary for most new projects, because the standard DOM API, the Fetch API and CSS transitions now cover its core features natively. It remains important as legacy infrastructure: a large share of existing websites, content management system themes and plugins still depend on it.
How jQuery works
The core of jQuery is the jQuery object, an array-like wrapper around a set of DOM elements. Calling $('.menu a') runs a CSS selector query and returns a wrapper containing every matching element. Methods called on the wrapper apply to all matched elements at once, so code such as $('.menu a').addClass('active') needs no explicit loop.
Most methods return the same wrapper, which enables method chaining: $('#panel').hide().addClass('closed').fadeIn(200). Getter methods, such as .text() or .attr('href'), read from the first element of the set, while setter forms of the same methods write to every element. This implicit iteration is convenient, but it also hides the number of elements affected.
Early versions shipped their own selector engine, Sizzle, to support CSS selectors in browsers that lacked querySelectorAll. Modern versions delegate to the native engine whenever possible and fall back to custom logic only for jQuery-specific pseudo-selectors such as :visible.
jQuery also stores per-element information in an internal data cache accessed through .data(), which reads HTML data attributes on first use and then keeps values in memory. Plugins extend the library by adding methods to $.fn, the shared prototype of every wrapper, which explains why thousands of third-party widgets could plug into the same chainable syntax.
Main modules of the jQuery API
The library groups its functions into modules that address separate browser tasks. The table below lists the most important ones and their typical calls.
| Module | Typical methods | Purpose |
|---|---|---|
| Selectors and traversal | $(), .find(), .closest() | Locate and navigate elements |
| Manipulation | .append(), .html(), .attr() | Change DOM content and attributes |
| Events | .on(), .off(), .trigger() | Attach and fire event handlers |
| Effects | .fadeIn(), .slideUp(), .animate() | Animate CSS properties over time |
| Ajax | $.ajax(), $.get(), .load() | Exchange data with a server |
| Deferred | $.Deferred(), .then() | Coordinate asynchronous results |
| Utilities | $.each(), $.extend() | Iterate and merge objects |
The events module standardized behavior across old browsers, including the event delegation pattern: $('#list').on('click', 'li', handler) attaches one listener to the parent and handles clicks on current and future li children through event bubbling. The Ajax module originally wrapped XMLHttpRequest, and the Deferred object anticipated the later standard Promise, although early versions did not follow the Promises/A+ specification.
jQuery compared with native browser APIs
Most jQuery features now have direct native equivalents in all evergreen browsers. The comparison below shows how common jQuery calls map to standard JavaScript.
| Task | jQuery | Native API |
|---|---|---|
| Select elements | $('.item') | document.querySelectorAll('.item') |
| Add a class | $(el).addClass('on') | el.classList.add('on') |
| Listen for events | $(el).on('click', fn) | el.addEventListener('click', fn) |
| Run code after DOM load | $(fn) | DOMContentLoaded event or defer script |
| Send a request | $.getJSON(url) | fetch(url).then(r => r.json()) |
| Animate | .fadeIn() | CSS transitions or Web Animations API |
The native versions are slightly more verbose but avoid an extra dependency of roughly 30 KB minified and compressed for the full build. Native code also integrates directly with async/await, ES modules and modern tooling, whereas jQuery was designed for global script tags.
Component frameworks such as React, Vue or Svelte follow a different model altogether. jQuery manipulates the DOM imperatively, step by step, while these frameworks derive the DOM declaratively from application state. Mixing both approaches on the same elements usually causes conflicts, because the framework overwrites changes it did not make.
When jQuery is still a reasonable choice
Choosing jQuery today is mainly a question of existing dependencies and team context, not capability. The decision table below summarizes typical situations.
| Situation | Recommendation | Reason |
|---|---|---|
| New single-page application | Do not use jQuery | Frameworks and native APIs cover its role |
| Existing site built on jQuery plugins | Keep it and update to the latest major version | Rewriting offers little value |
| CMS theme that already loads jQuery | Reuse the loaded copy | Avoids duplicate library versions |
| Small enhancement on a static page | Prefer native JavaScript | No dependency and less code to ship |
| Gradual modernization | Replace jQuery module by module | Reduces risk and allows testing |
Migration is often incremental: teams first remove deprecated methods with the jQuery Migrate plugin, which logs warnings for outdated calls, and then replace selectors, events and Ajax calls with native code.
Limitations, risks and common mistakes
The most serious risk in practice is running an outdated version. Releases before 3.5 contain known cross-site scripting (XSS) vulnerabilities in methods such as .html() and $.extend(), and many sites still load versions from the 1.x line because old plugins depend on them.
- Inserting untrusted HTML with
.html()or.append()executes embedded scripts and handlers; use.text()for user content. - Repeating the same selector inside loops forces repeated DOM queries; store the wrapper in a variable.
- Loading several jQuery copies on one page creates conflicts between plugins attached to different instances.
- Overusing animation methods runs JavaScript-driven animation on the main thread, which is less smooth than CSS transitions.
- Assuming one element when a selector matches many can apply changes far more widely than intended.
In everyday language
jQuery is a toolkit of shortcuts for web page scripting. Years ago, every browser understood JavaScript a little differently, so developers had to write the same feature several times. jQuery offered one simple way to write it that worked everywhere.
Today, browsers agree on most things and include many of those shortcuts themselves. That is why new websites rarely need jQuery, while many older sites still use it because replacing working code takes time and money.
Seen in the real world
A regional newspaper runs its website on a CMS theme built ten years ago. The theme loads jQuery 1.12 together with a photo carousel plugin and a comment form script. A security scan flags the old library because of known XSS vulnerabilities in that version.
The development team installs jQuery 3.7 with the Migrate plugin, which lists 14 deprecated calls in the theme code. They fix those calls, replace the outdated carousel with a native CSS solution and rewrite the comment form submission with the Fetch API. After two weeks of testing, the site passes the scan, page weight falls by about 45 KB and the remaining jQuery code can be removed gradually in later releases.