.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).
Syntax
Start with these common calls. Keep them short and readable.
jQuery
// 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);
Call
What it does
handler
function([jQuery]) — runs when DOM is ready
Recommended call
$(handler) since jQuery 3.0
Late bind
Still runs if DOM is already ready
$ argument
jQuery object — useful after noConflict()
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Include jQuery before your init script.
Step 2
Call $(function () { … }) (recommended) or $(document).ready(fn).
Step 3
Inside the handler, select elements, bind events, and start plugins.
Return Value
Return Value
Description
jQuery object
Most setters and traversing helpers return the jQuery collection so you can chain more methods.
jQuery Examples
Example 1 — Official Ready Demo
Update paragraph text when the DOM is ready — recommended shorthand.
jQuery
$(function () {
$("p").text("The DOM is now loaded and can be manipulated.");
});
3.0+. A throw in one handler does not stop the next.
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.