.ready(handler) (since 1.0) runs a function when the DOM is safe to manipulate — a good time to bind events and initialize plugins. Since jQuery 3.0, the recommended call is $(handler).
Remember
// Recommended (jQuery 3.0+)
$(function () {
// DOM is ready
});
// Equivalent (deprecated selection form, still works)
$(document).ready(function () {
// DOM is ready
});
// Not the same as window load (images/assets):
// $(window).on("load", fn);
Pass a function to jQuery; it runs as soon as the DOM is ready — even if you register late.
Include jQuery before your init script.
Call $(function () { … }) (recommended) or $(document).ready(fn).
Inside the handler, select elements, bind events, and start plugins.
Add more $(fn) calls if needed — they run in order.
Use $(window).on("load", fn) only when you need fully loaded assets.
Piece
Required?
Role
handler
Yes
function([jQuery]) — runs when DOM is ready
Recommended call
—
$(handler) since jQuery 3.0
Late bind
—
Still runs if DOM is already ready
$ argument
Optional
jQuery object — useful after noConflict()
Pseudocode
Pseudocode
call $(handler) // or .ready(handler)
if DOM is not ready yet:
queue handler for later
else:
run handler now
when DOM becomes ready:
for each queued handler in order:
try:
call handler(jQuery)
catch error:
call jQuery.readyException(error)
// jQuery 3.0+: continue with next handler
Reference
Cheat Sheet
Keep these facts handy while initializing page scripts.
3.0+. A throw in one handler does not stop the next.
Use. Split init into small modules safely.
Example 4 — noConflict + Ready $ Alias
Official pattern: the handler receives jQuery as $ even after releasing the global.
jQuery
var jq2 = jQuery.noConflict();
jq2(function ($) {
// $ is jQuery here; global $ may belong to another library
$("#out").text("Ready with local $ alias");
});
DOM ready
window load (assets done)
(ready always comes first)
How It Works
Ready. DOM elements exist — safe for most UI code.
Load. Images and other resources have finished.
Order. Ready always happens before window load.
Choose. Need image sizes? Prefer load. Otherwise use ready.
Edge Cases & Pitfalls
Watch for these when choosing ready vs load.
syntax
Prefer $(fn) in new code
Selection-based .ready() forms are deprecated since 3.0 and can imply the wrong wait.
load
Do not attach load only inside ready for dynamic scripts
If windowload already fired, a late listener never runs — common with dynamic $.getScript().
images
$("img").ready(fn) does not wait for images
It still waits for the document. Use window load or per-image events for asset timing.
removed
.on("ready") is gone
Removed in jQuery 3.0. Migrate to $(fn).
Compatibility
Browser Support
.ready() has been part of jQuery since 1.0. Prefer $(handler) since 3.0. Works wherever your loaded jQuery build runs.
✓ Stable · jQuery 1.0+
jQuery .ready()
Universal across browsers that run your jQuery version. Prefer current jQuery 3.x and the $(fn) shorthand.
100%jQuery core
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
.ready()Universal
Bottom line: Safe for everyday apps. Use $(fn) for DOM setup; switch to window load only when assets must be fully loaded.
Analysis
Performance Notes
Approach
Cost
Best for
$(fn) DOM init
Cheap
Events, plugins, UI wiring
Several small ready handlers
Cheap
Modular init in order
Heavy work on every ready
Expensive
Avoid — defer non-critical work
Ready itself is inexpensive. Keep handlers focused on setup; move large computations or network work out of the critical path.
Remember
Key Takeaways
Role: run code when the DOM is safe to manipulate.
Prefer:$(function () { … }) since jQuery 3.0.
Late bind: handlers still run if the DOM is already ready.
Not load: use window load when assets must finish first.
One line:$(fn) is jQuery’s DOM-ready hook — use it for setup, not for waiting on images.
Frequently Asked Questions
.ready(handler) registers a function to run when the DOM is safe to manipulate — after HTML is parsed, usually before all images finish loading. Prefer the shorthand $(handler) since jQuery 3.0.
They are equivalent in timing. $(fn) is the recommended form since jQuery 3.0. Other forms such as $(document).ready(fn) still work but are deprecated because the selection does not change ready behavior.
Both relate to DOM parse completion. jQuery still runs a handler registered after the DOM is already ready. A native DOMContentLoaded listener added too late never runs.
Use $(fn) for DOM setup, event handlers, and plugins. Use $(window).on("load", fn) when you need fully loaded assets (for example image dimensions). DOM ready happens before window load.
Yes. Each $(fn) or .ready(fn) call adds another handler. They run in registration order. Since jQuery 3.0, an exception in one handler does not block later handlers (see readyException).
The ready handler receives the jQuery object as its first argument: jQuery.noConflict(); jQuery(function($){ /* $ is jQuery here */ });
No. That event form was deprecated in 1.8 and removed in jQuery 3.0. Use $(fn) instead.