jQuery .ready() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Core

Definition

.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);
CallWhat it does
handlerfunction([jQuery]) — runs when DOM is ready
Recommended call$(handler) since jQuery 3.0
Late bindStill runs if DOM is already ready
$ argumentjQuery object — useful after noConflict()

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Include jQuery before your init script.
Step 2Call $(function () { … }) (recommended) or $(document).ready(fn).
Step 3Inside the handler, select elements, bind events, and start plugins.

Return Value

Return ValueDescription
jQuery objectMost 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.");
});
Try It Yourself

How It Works

  1. Register. $(fn) queues the callback for DOM ready.
  2. Wait. jQuery runs it when elements are safe to use.
  3. Select. $("p") finds the paragraph in the page.

Example 2 — $(document).ready() Long Form

Same timing as the shorthand — kept here so you can read legacy code.

jQuery
$(document).ready(function () {
  $("#status").text("Ready via $(document).ready()");
});
Try It Yourself

How It Works

  1. Select. $(document) is common but unused for timing.
  2. Ready. .ready(fn) registers the same ready queue.
  3. Prefer. New code should use $(fn) instead.

Example 3 — Multiple Handlers in Order

Each $(fn) call appends another callback — they run first-in, first-out.

jQuery
$(function () {
  $("#log").append("A ");
});

$(function () {
  $("#log").append("B ");
});

$(function () {
  $("#log").append("C");
});
Try It Yourself

How It Works

  1. Queue. Each call adds another ready handler.
  2. Order. jQuery runs them in registration order.
  3. 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.

Next: holdReady() Method

Learn how legacy code pauses ready while plugins finish loading.

holdReady() Method tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful