jQuery — Introduction
What is jQuery?
jQuery is a JavaScript library created by John Resig in 2006. Its motto is "Write less, do more."
// Without jQuery
document.getElementById("demo").innerHTML = "Hello";
// With jQuery
$("#demo").html("Hello");
Core Features
- DOM Manipulation — Select, modify, add, remove elements
- Event Handling — Bind events elegantly
- AJAX — Fetch data without page reload
- Animations — Show, hide, fade, slide, animate
- Utilities — Date formatting, iteration, mapping
How jQuery Works
jQuery wraps the browser's native APIs, providing a consistent interface:
// jQuery handles cross-browser differences
$("p").on("click", function() {
$(this).toggleClass("active");
});
The $ Function
$ is just an alias for jQuery:
// These are identical
$(document).ready(function() { });
jQuery(document).ready(function() { });
DOM Ready
Always wrap jQuery code in a ready handler:
$(document).ready(function() {
// Code runs after DOM is fully loaded
});
// Shorthand
$(function() {
// Same thing
});
jQuery vs Modern JavaScript
| Feature | jQuery | Vanilla JS |
|---|---|---|
| Syntax | Concise | Verbose |
| Browser support | Excellent | Modern only |
| File size | 87KB | 0KB |
| Learning curve | Easy | Moderate |
| Performance | Good | Faster |
When to Use jQuery
- Legacy projects already using it
- Quick prototypes and demos
- WordPress and CMS plugins
- Projects requiring old browser support
When to Skip jQuery
- New projects with modern JS features
- React, Vue, or Angular applications
- Performance-critical applications
- Mobile-first projects
Mini Practice
- Compare jQuery and vanilla JS for selecting elements
- Write the same functionality both ways
- Load jQuery and test
$is available - Use
$(document).ready()
Up Next
Continue with Get Started — your first jQuery script.
Related Topics
Frequently Asked Questions about Introduction
What is Introduction in jQuery?
Introduction is a fundamental concept in jQuery. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Introduction?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Introduction.
Why is Introduction important in jQuery?
Introduction is essential for jQuery development. Understanding this concept will help you write better code and solve real-world problems more effectively.