jQuery Tutorial
Learn jQuery step by step: 56 lessons in 12 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started
- What jQuery Is and When to Use It Learn what jQuery is, why it was created, what it still solves in version 3, where you will meet it today and how it compares with plain modern JavaScript.
- Setup and Your First jQuery Script Add jQuery to a page from a CDN with a pinned version and integrity check, learn the $ and jQuery names, and write your first working script safely.
- The Document Ready Event Learn how jQuery's document ready handler works, how it differs from DOMContentLoaded and window load, and how jQuery 3 runs ready handlers asynchronously.
- The jQuery Object Understand what $() returns: a jQuery collection, not a DOM node. Learn length, indexing, .get(), .eq(), implicit iteration, chaining and getter vs setter results.
Selecting Elements
- Basic Selectors Master jQuery's basic selectors: tag, id, class, groups, descendant, child and sibling combinators, attribute selectors, and how they map to querySelectorAll.
- Filtering Selectors and jQuery Extensions Learn jQuery's filter selectors such as :first, :even, :not, :has, :contains, :visible and :checked, their costs, and why .filter() is often the better choice.
- Selector Performance and Caching Learn how to make jQuery selectors fast: cache jQuery objects, narrow the search with context and .find(), avoid over-qualified selectors and measure with console.time.
- Filtering Methods Narrow a jQuery selection with .filter(), .not(), .has(), .is(), .first(), .last(), .eq() and .slice(), and transform it with .map() and .each().
Traversing the DOM
- Traversing Up the Tree Move from an element to its ancestors with jQuery .parent(), .parents(), .parentsUntil(), .closest() and .offsetParent(), plus patterns for event targets.
- Traversing Down and Sideways Walk down to children and descendants and sideways to siblings with jQuery .children(), .find(), .contents(), .siblings(), .next(), .nextAll(), .prev() and more.
- Working with Collections Loop over jQuery collections with .each() and $.each, build arrays with .map() and .get(), combine sets with .add() and .addBack(), and unwind chains with .end().
Manipulating the DOM
- Getting and Setting Content Read and change element content with jQuery .text(), .html() and .val(), use setter functions, and learn why .html() with user input is an XSS risk.
- Attributes and Properties Learn the difference between HTML attributes and DOM properties, when to use jQuery .attr() and .prop(), and how to handle checked, disabled and href correctly.
- Storing Data with .data() Use jQuery .data() to attach values to elements and read data-* attributes: camelCase keys, automatic type conversion, the internal cache and .removeData().
- Inserting Content Insert and create elements with jQuery: append, prepend, before, after, the appendTo family, moving versus cloning, and building lists from arrays safely.
- Removing, Replacing, Wrapping Remove, detach, empty, replace, wrap and clone elements with jQuery, and learn which methods keep event handlers and data and which throw them away.
- CSS and Classes Read and change styles with jQuery: the .css() getter and setter, computed values, addClass, removeClass, toggleClass with state, hasClass, and why classes win.
- Dimensions, Position and Scrolling Measure and place elements with jQuery: width, height, innerWidth, outerWidth(true), offset, position, scrollTop and scrollLeft, with box-sizing explained.
Events
- Handling Events Learn how to attach and remove jQuery event handlers with .on() and .off(), read the event object, tell this from event.target, and use namespaces.
- Event Delegation Use delegated .on(event, selector, handler) to handle clicks on dynamic elements, keep memory low, and avoid pitfalls with focus and mouseenter.
- The Event Object and Controlling Events Control events in jQuery: preventDefault, stopPropagation, stopImmediatePropagation, what return false really does, event.data, .one(), .trigger() and .triggerHandler().
- Mouse, Keyboard and Form Events A practical tour of jQuery's most used events: click, dblclick, mouseenter, keydown, input, change, focusin, resize and scroll, with throttling for busy events.
- Custom Events and Pub/Sub Create your own jQuery events with .trigger(), pass extra parameters, namespace them, and build a tiny pub/sub event bus with $({}) to decouple components.
Effects and Animation
- Showing and Hiding Use jQuery .show(), .hide() and .toggle() with speeds, callbacks and the display property, compare them to CSS classes, and keep hidden content accessible.
- Fading and Sliding Learn jQuery's fade and slide effects: fadeIn, fadeOut, fadeToggle, fadeTo, slideDown, slideUp, slideToggle, easing, callbacks and a working accordion.
- Custom Animations with .animate() Master jQuery .animate(): numeric properties, relative values, per-property easing, step and progress callbacks, color limits, fx.off and scrollTop.
- The Animation Queue Understand the jQuery animation queue: chaining, .stop(), .finish(), .delay(), .queue(), .dequeue(), custom queues, hover pile-ups and .promise().
AJAX
- AJAX with $.ajax() Learn jQuery $.ajax(): the settings object, method, data, dataType, success and error callbacks, statusText, headers, timeout and contentType, with runnable examples.
- $.get, $.post, $.getJSON and .load() Use jQuery's AJAX shortcuts: $.get, $.post, $.getJSON, $.getScript and .load() with fragment selectors, plus $.param serialization, all with runnable stand-ins.
- Deferreds, Promises and Ajax Events Work with the jqXHR promise: done, fail, always, then, $.when for parallel requests, jQuery 3 Promises/A+ rules, global ajax events, ajaxPrefilter and fetch.
- Real-World AJAX Patterns Learn the AJAX patterns used in real jQuery apps: loading states, error handling with retries, safe JSON rendering, pagination, debounced live search and CSRF headers.
Forms
- Working with Form Controls Read and set form values with jQuery: .val() for inputs, selects, checkboxes and radios, :checked and :selected, disabling, focus, .serialize() and .serializeArray().
- Form Validation Validate forms with jQuery: handle submit, check required fields and patterns, show accessible inline errors with aria-invalid and aria-describedby, and use browser validation.
Plugins and Utilities
- Utility Functions Learn the jQuery utility functions: $.extend (shallow and deep), $.each, $.map, $.grep, $.inArray, $.isPlainObject, and which old helpers are deprecated in favour of native JavaScript.
- Writing Your Own Plugin Write your own jQuery plugin with $.fn: keep chaining by returning this, merge default options, store per-element state with .data(), add methods and clean up namespaced events.
- Using Plugins and jQuery UI Choose and vet jQuery plugins, load scripts in the right order, use jQuery UI widgets like datepicker, sortable and dialog, apply noConflict and know when to pick alternatives.
- jQuery UI Interactions: Draggable, Droppable, Resizable, Selectable, Sortable Learn the five jQuery UI interactions: draggable, droppable, resizable, selectable and sortable, with options, events, methods and a working drag-and-drop example.
- jQuery UI Form Widgets: Autocomplete, Datepicker, Slider, Spinner and More Enhance forms with jQuery UI: autocomplete, datepicker, slider, spinner, selectmenu, button, checkboxradio and controlgroup, with options, events and theming.
- jQuery UI Dialog, Tabs, Accordion, Menu, Progressbar, Tooltip and Theming Build page structure with jQuery UI: dialog, tabs, accordion, menu, progressbar and tooltip, plus widget factory methods, events and theming with ThemeRoller.
- jQuery Mobile: Overview and Why It Faded Understand jQuery Mobile: the single-page model, data-role attributes, how to load it, a small multi-page example, and why modern projects use responsive CSS instead.
- DataTables with jQuery Turn HTML tables into sortable, searchable, paged grids with the DataTables plugin: array and AJAX data, column search, events, the API, child rows and several tables.
Migration and Performance
- What Changed in jQuery 3 See which jQuery APIs were removed or deprecated in version 3, how the slim build and the Migrate plugin work, and how to upgrade old 1.x and 2.x code safely.
- From jQuery to Modern JavaScript Translate common jQuery tasks into plain modern JavaScript: selecting, classes, events, delegation, attributes, fetch, animation. Learn when to keep jQuery.
- Best Practices, Performance and Pitfalls Write fast, safe jQuery: cache selections, batch DOM changes, use delegation, clean up with .off(), avoid XSS with .text() and escape selectors from user input.
- Testing and Debugging jQuery Code Structure jQuery code into testable modules, check selectors, build a tiny assertion helper, use fixtures for DOM tests and debug with the console and devtools.
Projects
- Project: To-Do List Build a to-do list in jQuery: add, complete and delete tasks, filter with event delegation, count what is left and animate items, all from in-memory state.
- Project: Image Gallery and Lightbox Build a thumbnail gallery with delegated clicks and a fade-in lightbox that supports keyboard navigation, focus trapping, Escape to close and restored focus.
- Project: Tabs and Accordion Components Build two reusable jQuery plugins, an accessible tabs widget and a slide accordion, with ARIA roles, keyboard support and configuration through data attributes.
- Project: Live Search and Sortable Table Build a data table that loads rows from a stand-in AJAX call, filters as you type with match highlighting, sorts by column with .sort() and shows an empty state.
- Project: Multi-Step Form Wizard Build a multi-step form wizard in jQuery with per-step validation, an animated progress bar, focus management and a summary screen that prints the answers.
- Project: Calculator Build a working calculator with jQuery: lay out the keypad, handle digits, decimals and operators with one delegated handler, and avoid floating-point surprises.
- Project: Tic-Tac-Toe Build tic-tac-toe with jQuery: draw the board, alternate players, reject invalid moves, detect wins and draws with a lookup table, and reset the game.
- Project: Image Slider, Magnifier and Spotlight Build three pointer-and-animation projects with jQuery: an auto-playing image slider, a hover image magnifier and a spotlight that follows the mouse.
Practice and Review
- Practice Exercises with Solutions Fifteen graded jQuery exercises on selectors, traversal, DOM changes, events, effects, AJAX stand-ins and plugins, each with a hint and a runnable solution.
- jQuery Interview Questions Thirty common jQuery interview questions with short answers and code: .attr vs .prop, delegation, ready vs load, chaining, noConflict, deferreds and migration.
- jQuery Cheat Sheet A one-page jQuery 3 cheat sheet with selectors, traversal, DOM changes, events, effects, AJAX and utilities, each next to its modern JavaScript equivalent.