Opens in a new tab

Why Do We Need jQuery When JavaScript Works Fine? Is jQuery Dead?

Why Do We Need jQuery When JavaScript Works Fine? Is jQuery Dead?

Every few months a junior developer asks us the same question: “Should I learn jQuery, or is it dead?” It is a fair question. Modern tutorials barely mention it, job posts ask for React or Vue, and plain JavaScript can now do almost everything jQuery was famous for.

And yet, if you open the source code of a random business website today, there is a good chance jQuery is loaded on it. So is jQuery dead, or is it everywhere? The honest answer is “both”, and in this article we will explain why, show the plain JavaScript version of the jQuery code you already know, and help you decide when each one makes sense.

Why jQuery became so popular

jQuery was released in 2006, at a time when building for the web was painful. Internet Explorer, Firefox and Safari all behaved differently. Even something simple like attaching a click event needed different code for different browsers. Selecting elements by class name was not built into older browsers at all.

jQuery solved this with one small library and one simple idea: find elements with a CSS selector, then do something to them.

$('.menu-toggle').on('click', function () {
  $('.menu').slideToggle();
});

It worked the same in every browser. For developers in 2008, that felt like magic, and jQuery quickly became the most used JavaScript library on the web.

What changed

Over the next decade, browsers caught up. The good ideas from jQuery were added directly to JavaScript and the browser itself:

  • document.querySelector() and querySelectorAll() gave us CSS selectors natively.
  • classList made adding and removing classes easy.
  • fetch() replaced the old, clumsy XMLHttpRequest for loading data.
  • CSS transitions and animations took over most of what jQuery’s .animate() and .fadeIn() did, with better performance.
  • Internet Explorer was retired, and modern browsers now follow the same standards closely.

The main problem jQuery was built to solve, browser differences, mostly disappeared. That is why new projects rarely include it.

jQuery vs plain JavaScript, side by side

If you already know jQuery, here is how the common tasks look in modern JavaScript. You will notice the plain version is a little longer, but not by much.

Task jQuery Plain JavaScript
Select one element $('#title') document.querySelector('#title')
Select many elements $('.card') document.querySelectorAll('.card')
Add a class $el.addClass('active') el.classList.add('active')
Toggle a class $el.toggleClass('open') el.classList.toggle('open')
Change text $el.text('Hi') el.textContent = 'Hi'
Read an attribute $el.attr('href') el.getAttribute('href')
Click event $el.on('click', fn) el.addEventListener('click', fn)
Run when page is ready $(function () { ... }) document.addEventListener('DOMContentLoaded', ...)
Hide an element $el.hide() el.hidden = true

The one difference that catches people out

jQuery automatically applies an action to every matched element. Plain JavaScript does not. This jQuery line adds a class to all cards:

$('.card').addClass('visible');

In plain JavaScript you loop over them yourself:

document.querySelectorAll('.card').forEach(card => {
  card.classList.add('visible');
});

Loading data: $.ajax vs fetch

// jQuery
$.getJSON('/api/posts', function (posts) {
  console.log(posts);
});

// Plain JavaScript
const response = await fetch('/api/posts');
const posts = await response.json();
console.log(posts);

With async and await, the modern version reads almost like plain English.

Event delegation

jQuery made it easy to handle clicks on elements that do not exist yet, such as items added later by a script:

// jQuery
$(document).on('click', '.delete-btn', function () { ... });

// Plain JavaScript
document.addEventListener('click', event => {
  const button = event.target.closest('.delete-btn');
  if (button) { /* ... */ }
});

The closest() method makes the plain version just as reliable.

So, is jQuery dead?

No, but it is retired from the front line. Think of it like a reliable old car: it still runs perfectly, lots of people still drive it every day, but few people would choose it if they were buying new today.

Where jQuery is still very much alive

  • WordPress. WordPress still ships with jQuery, and thousands of themes and plugins depend on it. If you build or maintain WordPress sites, you will read and write jQuery regularly.
  • Older websites and admin panels. Many business systems built ten years ago run on jQuery and work perfectly well. Rewriting them just to remove jQuery rarely makes business sense.
  • Plugins that need it. Some sliders, date pickers and form libraries still require jQuery.

Where you should skip it

  • New projects. Plain JavaScript can do everything you need, so loading an extra library (around 30 KB compressed) just for shorter syntax is hard to justify.
  • Apps built with React, Vue or Svelte. These frameworks manage the page for you. Changing the page directly with jQuery fights against them and causes bugs.
  • Performance focused sites. Every script you remove helps your page load faster, which helps both visitors and search rankings.
A real example: every tool on our own free online tools site, from the word counter to the time zone converter, is written in plain JavaScript with no jQuery and no framework. The pages stay small and load fast, even on slow mobile connections.

Is jQuery dead for beginners? Should you still learn it?

Our advice to beginners is simple:

  1. Learn plain JavaScript first. Selecting elements, events, fetch, arrays and objects. This knowledge works everywhere and never goes out of date.
  2. Learn enough jQuery to read it. If you plan to work with WordPress or existing client sites, you will see it often. Once you know plain JavaScript, picking up jQuery takes an afternoon.
  3. Then learn a framework if you need one. React or Vue makes sense for complex, app like interfaces. For a brochure website, plain JavaScript is usually enough.

How to move a small site away from jQuery

If you have a site with a few jQuery snippets and want to remove the library, do it gradually:

  1. Search your theme for $( and jQuery( to see how much code depends on it.
  2. Check which plugins load jQuery. If a plugin needs it, you cannot remove it until that plugin is replaced.
  3. Rewrite your own snippets one at a time using the table above, and test each one.
  4. Only remove jQuery once nothing on the page uses it. On WordPress, be careful: removing it from the front end can break plugins in ways that are easy to miss.

Final thoughts: is jQuery dead?

jQuery did its job so well that browsers adopted its best ideas, and that is exactly why we need it less today. It is not something to be embarrassed about using in a WordPress theme, and it is not something to add to a brand new project by habit either.

If you want to see how jQuery compares with a modern framework, read our article on React vs jQuery and the differences between them.