Nodea — logo

jQuery

jQuery is a lightweight, open-source JavaScript library that streamlines working with the HTML document tree (DOM), event handling, animations and AJAX requests. Its motto — "write less, do more" — captures the point: code that would take a dozen lines in plain JavaScript often collapses into a single chained expression in jQuery. For many years it was the default choice of front-end developers, largely because it smoothed over the incompatibilities between browsers.

How jQuery works

The heart of the library is the $() function, which acts as both a selector and a wrapper around page elements. Pass it a CSS selector and you get a jQuery object containing the matching nodes, on which you can immediately call methods:

  • DOM manipulation.text(), .html(), .append() and .addClass() change the content and appearance of elements;
  • event handling.on('click', …) wires up responses to clicks, scrolls or form submissions;
  • AJAX$.ajax(), $.get() and $.post() fetch data from the server without reloading the page;
  • animations.fadeIn(), .slideUp() and .animate() produce smooth effects without hand-writing CSS keyframes.

A defining feature is chaining: most methods return the same jQuery object, so successive operations can be appended one after another.

Practical application

jQuery powers interactive elements on countless sites: toggling menus, form validation, carousels, background content loading and dynamic filters. In the WordPress ecosystem it remains ubiquitous — the CMS core and thousands of plugins ship it automatically, so familiarity with the library still pays off when maintaining and extending existing sites on a typical hosting account.

In greenfield projects its role is shrinking. Modern browser APIs and frameworks such as React and Vue.js have taken over most of its use cases. jQuery can also become unnecessary overhead — an extra file to download that slows the page if you only use a handful of its helpers. Even so, thanks to the sheer scale of its deployment, jQuery will remain part of the web for a long time yet.

Powiązane pojęcia

Najczęstsze pytania

Is jQuery still relevant today?

Less so for new projects — native browser APIs such as querySelector, fetch and classList now cover most of what jQuery once made easy. It remains important, though, for maintaining older sites and the countless WordPress themes and plugins that still depend on it.

How is jQuery different from React?

jQuery is a library for imperatively manipulating an existing DOM — you describe each change step by step. React is a library for building user interfaces declaratively: you describe the target state of the view and React updates the real DOM for you via a virtual DOM.