What it is
JS library
DOM selection, events, effects, and AJAX with a concise $() API.

This page is a self-contained introduction to jQuery—a popular JavaScript library for front-end interactivity. You will learn how to load it, use $() and document ready, and where jQuery still fits next to vanilla JS and modern frameworks.
JS library
DOM selection, events, effects, and AJAX with a concise $() API.
CDN script
Load jQuery 3.7.1 from a CDN before your own scripts.
Syntax
Wait for the DOM, then select and chain methods on elements.
Interact
Update content, toggle classes, and bind click handlers.
5 labs
CDN setup, hide, text, click toggle, and fade effects.
Callbacks
Continue to callbacks, then selectors, events, and AJAX.
jQuery is a fast, small, and feature-rich JavaScript library that simplifies HTML document traversal and manipulation, event handling, animation, and AJAX interactions for rapid web development.
It lets developers write less code while achieving more—especially when maintaining existing sites or building interactive pages without a heavy framework. jQuery does not replace JavaScript. It is written in JavaScript and provides a friendly API on top of the browser’s DOM. The famous $ function is shorthand for “find these elements and let me work with them.”
One consistent $() API covers selection, events, effects, and AJAX—and still powers a huge share of WordPress themes, admin UIs, and legacy sites.
Common DOM tasks that take many vanilla lines fit in one chained expression.
jQuery smooths older browser quirks that still appear in enterprise environments.
$("#box").hide().fadeIn() reads left to right on one selection.
Huge plugin ecosystem plus $.get / $.ajax for server data.
In short: load jQuery, wait for DOM ready, select with $(), and chain methods—without forgetting plain JavaScript underneath.
Include jQuery via CDN or a local file, then wrap your code in a document-ready handler. These tutorials use jQuery 3.7.1.
Add a <script> tag before your own scripts. A CDN is fine for demos; pin a version in production.
<!-- Place before your own scripts -->
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script src="app.js"></script> jQuery revolves around selecting HTML elements and performing actions on them:
$(function () {
$("#elementID").hide();
}); $(function () { ... }) is shorthand for $(document).ready(...). The selector $("#elementID") targets an element with id="elementID".
Powerful selectors let you target nodes by ID, class, tag, or CSS-style queries, then call methods like .html(), .append(), or .remove().
Use .on("click", handler) (or shorthand .click(handler)). Event delegation lets you attach one listener to a parent and handle events from dynamically added children.
Methods like .fadeIn(), .fadeOut(), .slideToggle(), and .animate() build smooth transitions without low-level timing code.
Learn basic JavaScript first (variables, functions, DOM). Then jQuery will feel like a shortcut for repetitive tasks such as selecting elements and attaching click handlers.
| Concept | What it does | Typical use |
|---|---|---|
$() / jQuery() | Factory: find, create, wrap, or run on DOM ready | Start every selection |
| Chaining | Call multiple methods on one selection | $("#box").hide().fadeIn() |
.on() | Attach event listeners | Clicks, forms, keyboard |
.html() / .text() | Read or update content | Messages and templates |
.css() / .addClass() | Change styles and classes | UI state and themes |
| Effects | .show(), .hide(), .fadeToggle() | Reveal and hide panels |
| AJAX | $.get(), $.ajax() | Fetch JSON or HTML |
| Plugins | Third-party extensions on top of jQuery | Sliders, date pickers, validate |
| Task | Example |
|---|---|
| Document ready | $(function () { ... }); |
| Select by ID | $("#header") |
| Select by class | $(".btn") |
| Click handler | $("#btn").on("click", fn); |
| Set text | $("#msg").text("Hello"); |
| GET request | $.get("/api/data", callback); |
| Library version | $.fn.jquery → 3.7.1 |
Same outcome—different trade-offs for syntax, dependencies, and scale.
$("#btn").on("click", fn)Concise DOM API, plugins, strong legacy support
querySelector + addEventListenerNo extra dependency; modern browsers cover most needs
components + stateBest for large SPAs with structured UI state
Pick jQuery, vanilla JS, or a framework based on the project—not fashion alone.
Themes, plugins, and admin scripts often already ship jQuery—extend them cleanly.
Menus, toggles, and small animations are fast to write with $() chaining.
Need a date picker or slider that assumes jQuery? The library is the glue.
Greenfield SPAs usually choose React/Vue or plain querySelector + fetch.
Key benefit: jQuery remains the fastest path to maintain and extend the enormous amount of existing jQuery code on the web.
Five starter snippets. Use View Output here, or Try It Yourself to edit the lab.
After the script runs, $ is global. Log the version to confirm the load order.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery Demo</title>
</head>
<body>
<p id="demo">Hello, jQuery!</p>
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script>
$(function () {
console.log("jQuery version:", $.fn.jquery);
});
</script>
</body>
</html> The CDN script defines $ and jQuery. Your inline script waits for DOM ready, then reads $.fn.jquery—the version string shipped with that build.
Requires HTML: <div id="banner">Welcome!</div>. When the page loads, the banner disappears immediately.
$(function () {
$("#banner").hide();
}); $("#banner") selects the element by ID. .hide() sets display: none. Running inside $(function(){}) guarantees the node exists before selection.
.text() sets plain text (safe from HTML injection). .html() parses markup inside the element.
$(function () {
$("#greeting").text("Welcome back!");
$("h1.title").html("<em>Dashboard</em>");
}); The first call replaces text content of #greeting. The second injects italic markup into every h1.title. Prefer .text() for untrusted or user-provided strings.
Each click adds or removes the open class on #sidebar. Pair with CSS such as .open { display: block; } for a simple menu.
$(function () {
$("#menu-btn").on("click", function () {
$("#sidebar").toggleClass("open");
});
}); .on("click", ...) binds a listener once. Inside the handler, .toggleClass("open") flips the class list so CSS can show or hide the sidebar.
Chaining .hide() then .fadeIn(800) creates a smooth 800 ms fade-in when the page loads.
$(function () {
$("#alert").hide().fadeIn(800);
}); The selection stays the same across the chain: hide immediately, then animate opacity over 800 milliseconds. Effects return the jQuery object so you can keep chaining.
Where jQuery still earns a place in a project.
Menus, modals, tabs, and form helpers without a full SPA framework.
Example: $("#menu").toggleClass("open")
Many themes already enqueue jQuery for customizer and front-end scripts.
Example: theme.js using $
Load HTML fragments or JSON and inject them into a container.
Example: $.get("/partial", html => $("#main").html(html))
Fade, slide, and simple .animate() transitions for alerts and panels.
Example: $("#alert").fadeIn(400)
Older IE-era codebases still rely on jQuery’s consistent API.
Example: intranet tools and CRM UIs
Widgets and plugins that expect $ as the host library.
Example: datepickers and autocomplete
Why teams still reach for jQuery.
Select once, then chain hide, fade, and class updates in a readable line.
A consistent API across browsers that still show up in enterprise and CMS work.
Thousands of UI widgets and helpers build on the same $ foundation.
$.get, $.post, and $.ajax simplify common async patterns.
Small habits that keep jQuery code predictable.
Wrap scripts in $(function(){}) so selectors find real elements.
Store var $nav = $("#nav"); when you use the same node many times.
These pages use 3.7.1. Check $.fn.jquery if demos behave differently.
Mistakes that commonly trip up new jQuery users.
$ is not defined means the library script has not run yet.
→ Put the jQuery <script> above your own code.
Scripts in <head> without ready find zero elements.
→ Use $(function(){ ... }) or place scripts at the end of <body>.
.html(userInput) can open XSS holes.
→ Prefer .text() for user-provided content.
Binding .on("click") again after every AJAX refresh multiplies clicks.
→ Use event delegation on a stable parent, or .off() before rebinding.
The browser parses your page and downloads the jQuery library from CDN or a local file.
Your $(function(){...}) callback runs once elements exist in the document.
$() finds nodes; methods update the DOM, bind events, or start animations.
Users see toggles, fades, and AJAX-loaded content without full page reloads.
$ call.Quick Takeaway: Load jQuery, wait for ready, select with $(), and chain methods—then decide when vanilla JS or a framework is a better fit.
jQuery is a JavaScript library. After you load it, $() helpers run in browsers that the 3.x docs list. Logos use the shared browser-image-sprite.png sprite from this project.
Load the minified build, wait for DOM ready, then select and chain. Behavior is consistent because jQuery implements the helpers.
Bottom line: Safe once jquery-3.7.1.min.js (or equivalent) is loaded. These tutorials pin version 3.7.1.
jQuery is a compact toolkit for DOM scripting: load it, wait for ready, call helpers on $, and ship interactive pages quickly. It remains essential for legacy maintenance even when new greenfield apps choose vanilla JS or frameworks.
Continue to Callbacks next, then practice selectors, events, and AJAX on real pages.
Pin jQuery 3.7.1 in demos, and never skip document ready when selecting elements.
$(function(){}) so the DOM exists before you select elements.on() for event binding (supports delegation).text() for user-provided content to avoid XSSvar $nav = $("#nav"); when reused.html() with untrusted user input$ alias conflict—use jQuery.noConflict() if neededYour gateway to callbacks, selectors, events, effects, and AJAX.
Helpers on $, not a new language
Script tag before your code
Setup$(function(){})
Select once, call many methods
APITutorials pin 3.7.1
CDNInclude jQuery with a <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script> tag, wait for the DOM with $(function() { ... }), select elements with $(), and chain methods like .hide(), .on('click'), and .fadeIn(). jQuery was released in 2006 by John Resig and, at its peak, ran on the majority of the top million websites.
Load jQuery 3.7.1 in the live editor, then continue to Callbacks.
9 people found this page helpful