jQuery Introduction

What Is jQuery?
jQuery is a fast, lightweight JavaScript library that simplifies DOM selection, events, animations, and AJAX. It wraps browser APIs in a concise $() syntax so common front-end tasks take fewer lines.
Core pattern:
$(selector).action()
Ready handler (run after HTML parses):
$(function () { ... })
Same idea: $(document).ready(function () { ... }) These tutorials use jQuery 3.7.1. jQuery still powers many legacy sites, WordPress themes, and dashboards even as newer apps prefer vanilla JS or frameworks.
Why Use jQuery?
Plain JavaScript can do everything jQuery does—jQuery just makes everyday DOM work shorter and more consistent across browsers.
| Need | How jQuery helps |
|---|---|
| Select elements | CSS-style selectors via $() |
| Handle clicks & forms | .on() with easy event delegation |
| Animate UI | Built-in .fadeIn(), .slideToggle(), and more |
| Fetch data | Simple AJAX helpers like $.get and $.ajax |
How jQuery Runs
Your page loads jQuery, then your script talks to the DOM through $:
| Step | What happens |
|---|---|
| 1. Load | Browser loads jQuery from CDN or a local file |
| 2. Ready | $(function(){…}) waits until the HTML is parsed |
| 3. Select | $("#id"), $(".class"), or any CSS selector |
| 4. Act | Chain methods: .text(), .on(), .fadeIn() |
Your First jQuery Script
Include the CDN, then update a paragraph when the DOM is ready:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery CDN setup</title>
</head>
<body>
<h1>jQuery CDN demo</h1>
<p id="status">Loading jQuery...</p>
<!-- Place before your own scripts -->
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script>
$(function () {
$("#status").text("jQuery " + $.fn.jquery + " is ready.");
});
</script>
</body>
</html> How It Works
1. Load. The CDN script defines $ / jQuery on the page.
2. Ready. $(function () { ... }) runs after the HTML is parsed.
3. Update. $("#status").text(...) selects the paragraph and sets its text.
Next, explore callback objects in jQuery Callbacks.
jQuery vs Vanilla vs Frameworks
Pick the tool that matches the project:
| Option | Style | Choose when… |
|---|---|---|
| jQuery | Library helpers on the DOM | Legacy sites, quick enhancements, WordPress |
| Vanilla JS | Built-in browser APIs | No dependency; modern browsers only |
| React / Vue | Component frameworks | Large SPAs with complex UI state |
Same job, two styles
Hide an element with id banner:
$("#banner").hide(); document.getElementById("banner").style.display = "none"; When to use which
| Use jQuery when… | Prefer vanilla / frameworks when… |
|---|---|
| You maintain an existing jQuery codebase | You start a greenfield modern app |
| You need short DOM/event helpers quickly | You want zero library weight |
| Plugins or WordPress already expect it | You need a component-driven SPA |
Core Building Blocks
These pieces show up in almost every jQuery script:
| Concept | What it does | Example |
|---|---|---|
$() | Select elements or wrap the ready handler | $("#msg") |
| Chaining | Call several methods on the same set | $("#x").hide().fadeIn() |
| Events | Listen for user actions | .on("click", fn) |
| DOM | Read or change content and attributes | .text(), .html(), .attr() |
| Effects | Show, hide, and animate | .fadeOut(), .slideUp() |
| AJAX | Talk to a server without reloading | $.get(url) |
Where Is jQuery Used?
jQuery still appears across a lot of the live web:
| Use case | Why jQuery fits |
|---|---|
| Legacy websites | Already wired; cheaper to extend than rewrite |
| WordPress themes & plugins | Many still ship jQuery by default |
| Admin dashboards | Quick toggles, tables, and form helpers |
| Light interactivity | Menus, modals, and tabs without a full SPA |
| AJAX forms | Submit and update page sections without reload |
| Prototypes | Fast DOM demos with little setup |
Key Takeaways
- jQuery is a JavaScript library—not a separate language.
- Pattern:
$(selector).action()after DOM ready. - Load order: jQuery script first, then your code.
- Today: great for legacy; learn JS fundamentals either way.
One line: jQuery shortens DOM work with $()—next, learn callbacks.
Frequently Asked Questions
Did you know?
Include 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().
Next: jQuery Callbacks
See how jQuery manages lists of callback functions.
11 people found this page helpful
