jQuery .ready() Method

Beginner
7 min read
Updated: Oct 2026
5 examples
Live preview

What Is .ready()?

.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);
NeedUse
DOM init / bind handlers$(function () { … })
Wait for images/assets$(window).on("load", fn)
Pause ready globallyjQuery.holdReady()
Sync ready errorsjQuery.readyException
Free $ for other libsjQuery.noConflict()

How to Use .ready()

Pass a function to jQuery; it runs as soon as the DOM is ready — even if you register late.

  1. Include jQuery before your init script.
  2. Call $(function () { … }) (recommended) or $(document).ready(fn).
  3. Inside the handler, select elements, bind events, and start plugins.
  4. Add more $(fn) calls if needed — they run in order.
  5. Use $(window).on("load", fn) only when you need fully loaded assets.
PieceRequired?Role
handlerYesfunction([jQuery]) — runs when DOM is ready
Recommended call—$(handler) since jQuery 3.0
Late bind—Still runs if DOM is already ready
$ argumentOptionaljQuery 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

Cheat Sheet

Keep these facts handy while initializing page scripts.

TopicDetail
Recommended$(function () { … })
Long form$(document).ready(fn) ⚠ deprecated selection style
SincejQuery 1.0 · recommend $(fn) from 3.0
vs DOMContentLoadedjQuery still runs late-registered handlers
vs window loadReady = DOM · Load = DOM + assets
Multiple callsRun in registration order
Exceptions (3.0+)One failure does not block later handlers
Removed API.on("ready", fn) removed in 3.0

Live Preview

Because this page is already loaded, $(fn) runs immediately — the same API you use at the top of a script.

Demo target: the status line below. Late $(fn) still executes because the DOM is ready.

Status: waiting for Run…

Result
Ready — pick an action and click Run.

jQuery Examples

Short, copy-ready snippets. Prefer $(function () { … }) for new code.

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.
  4. Update. .text() replaces the placeholder message.

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.
  4. Why deprecated. Selection forms suggest wrong waits (e.g. images).

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.
  4. 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");
});
Try It Yourself

How It Works

  1. Release. noConflict() gives global $ back.
  2. Call. Use the returned jq2 (or jQuery) to register ready.
  3. Alias. The first argument is the jQuery object — name it $.
  4. Write. Inside the handler, keep familiar $("…") code.

Example 5 — Ready vs Window load

Ready fires when the DOM is parsed; load waits for images and other assets.

jQuery
$(function () {
  $("#log").append("DOM ready\\n");
});

$(window).on("load", function () {
  $("#log").append("window load (assets done)\\n");
});
Try It Yourself

How It Works

  1. Ready. DOM elements exist — safe for most UI code.
  2. Load. Images and other resources have finished.
  3. Order. Ready always happens before window load.
  4. 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 window load 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).

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 Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All 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.

Performance Notes

ApproachCostBest for
$(fn) DOM initCheapEvents, plugins, UI wiring
Several small ready handlersCheapModular init in order
Heavy work on every readyExpensiveAvoid — defer non-critical work

Ready itself is inexpensive. Keep handlers focused on setup; move large computations or network work out of the critical path.

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.

Next: holdReady() Method

Learn how legacy code pauses ready while plugins finish loading.

holdReady() tutorial →

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