jQuery .resize() Method

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

What Is .resize()?

.resize() is jQuery’s legacy shorthand (since 1.0) for binding or triggering the browser resize event — typically on window. It is deprecated since 3.3 but still works in jQuery 3.x. Prefer .on("resize") / .trigger("resize").

Remember
// Deprecated (since 3.3) — still works in jQuery 3.x
$(window).resize(function () {
  // viewport size changed
});

$(window).resize(); // trigger

// Modern replacements
$(window).on("resize", handler);
$(window).trigger("resize");
NeedUse
New code (bind)$(window).on("resize", fn)
New code (trigger)$(window).trigger("resize")
Legacy bind$(window).resize(fn) ⚠
Legacy trigger$(window).resize() ⚠
Remove handler$(window).off("resize", fn)

How to Use .resize()

Recognize the legacy call, bind on window, and migrate to .on() / .trigger().

  1. Bind with $(window).resize(handler) (legacy) or .on("resize", handler) (preferred).
  2. Optionally pass eventData: .resize(data, handler) → .on("resize", data, handler).
  3. Trigger with no-arg .resize() (legacy) or .trigger("resize") (preferred).
  4. Debounce expensive layout / chart work inside the handler.
  5. Remove with .off("resize", handler) — not .unbind().
PieceRequired?Role
windowYes (typical)Standard target for viewport resize
handlerFor bind formfunction(event)
eventDataOptional (1.4.3+)Extra data as event.data
DebounceRecommendedLimit how often expensive work runs

Pseudocode

Pseudocode
call $(window).resize(handler)
    → internally: $(window).on("resize", handler)

call $(window).resize()
    → internally: $(window).trigger("resize")

when browser viewport size changes:
    fire resize on window
        for each registered handler:
            call handler(event)

to migrate:
    .resize(fn)      → .on("resize", fn)
    .resize(data, fn) → .on("resize", data, fn)
    .resize()        → .trigger("resize")

Cheat Sheet

Quick map from the deprecated shorthand to modern APIs.

TopicDetail
Legacy bind$(window).resize(handler) ⚠ deprecated 3.3
Modern bind$(window).on("resize", handler)
Legacy trigger$(window).resize()
Modern trigger$(window).trigger("resize")
Unbind$(window).off("resize" [, handler])
Signaturefunction(event)
SinceMethod 1.0 · eventData 1.4.3 · deprecated 3.3
Call countBrowser-dependent — debounce heavy work

Live Preview

Run the legacy .resize() shorthand (still available in jQuery 3.x) and watch the handler update the log.

Demo uses deprecated .resize(). Prefer .on("resize") for new code. Drag the browser edge or click Trigger.

Result
Ready — resize the window or click Run.

jQuery Examples

Short, copy-ready snippets using the legacy shorthand. Prefer .on("resize") for new projects.

Example 1 — Basic $(window).resize(fn)

Canonical legacy pattern: append a message each time resize fires.

jQuery
$(window).resize(function () {
  $("#log").append(" Handler for resize called. ");
});
Try It Yourself

How It Works

  1. Bind. .resize(fn) on window registers a handler.
  2. Delegate. jQuery routes it to .on("resize", fn) internally.
  3. Resize. The browser fires the event when the viewport changes.
  4. Append. Each firing adds another message fragment.

Example 2 — .resize(eventData, handler)

Pass extra data (since 1.4.3). Modern form: .on("resize", data, fn).

jQuery
$(window).resize({ label: "viewport" }, function (event) {
  $("#out").text(
    event.data.label + ": " + $(window).width() + "px"
  );
});
Try It Yourself

How It Works

  1. Data. The object becomes event.data inside the handler.
  2. Resize. Viewport change fires the event.
  3. Read. Use event.data.label plus $(window).width().
  4. Migrate. Swap to .on("resize", data, fn) when refactoring.

Example 3 — No-arg .resize() Trigger

Fire the event programmatically. Prefer .trigger("resize") today.

jQuery
$(window).resize(function () {
  $("#out").text("Width: " + $(window).width() + "px");
});

$("#run").on("click", function () {
  $(window).resize(); // legacy trigger
});
Try It Yourself

How It Works

  1. Bind. The handler is registered first.
  2. Click. No-arg .resize() triggers the event.
  3. Run. Bound handlers execute immediately.
  4. Migrate. Replace with .trigger("resize") in new code.

Example 4 — Migrate to .on("resize")

Both bind the same event — .on() is the recommended API for new code.

jQuery
// Legacy — deprecated since jQuery 3.3
$(window).resize(function () {
  $("#out").text("Legacy: .resize(function(){ ... }).");
});

// Modern — use for new code
$(window).on("resize", function () {
  $("#out").text("Modern: .on('resize', function(){ ... }).");
});
Try It Yourself

How It Works

  1. Same event. Both register handlers for resize on window.
  2. Sugar. .resize(fn) already calls .on("resize", fn).
  3. Rename. Migration is a straight API change for simple bindings.
  4. Cleanup. Pair modern binds with .off("resize", fn).

Example 5 — Debounce Inside .resize()

Legacy bind, modern habit: wait until resizing pauses before heavy work.

jQuery
var timer;

function recalcLayout() {
  $("#box").text("Width: " + $(window).width() + "px");
}

$(window).resize(function () {
  clearTimeout(timer);
  timer = setTimeout(recalcLayout, 200);
});
Try It Yourself

How It Works

  1. Raw events. Resize can fire many times during a drag.
  2. Reset timer. Each event clears the previous timeout.
  3. Settle. Work runs only after 200ms of quiet.
  4. Same rule. Debounce applies whether you use .resize() or .on().

Edge Cases & Pitfalls

Watch for these when reading or migrating legacy resize code.

deprecated

Do not use in new code

.resize(handler) is deprecated since 3.3. Prefer .on("resize").

target

Bind on window

Viewport resize is delivered to window. Prefer $(window).resize(fn) / .on("resize").

count

Do not rely on call count

Some browsers fire continuously during a drag; others once at the end. Debounce instead.

removed?

Not removed like .error()

.resize() still exists in jQuery 3.x. .error() was removed in 3.0 — do not treat them the same.

Browser Support

The .resize() method has been part of jQuery since 1.0. Binding via .resize(handler) is deprecated since 3.3 but still functional in jQuery 3.x. Prefer .on("resize") / .trigger("resize").

✓ Deprecated · jQuery 1.0+

jQuery .resize()

Works wherever your loaded jQuery version runs. Prefer .on('resize') for new projects. Call frequency during a drag varies by engine.

100% With jQuery 3.x
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
.resize() Legacy API

Bottom line: Safe in legacy jQuery projects. Migrate bindings to .on('resize') and triggers to .trigger('resize') when updating code.

Performance Notes

ApproachCostBest for
Light log / width readCheapDebugging, simple labels
Debounced layout / chart redrawCheap–moderateResponsive UI updates
Heavy DOM work every resizeExpensiveAvoid — debounce or throttle

Legacy and modern binds have the same cost. Keep handlers light, and debounce anything that measures or redraws the DOM.

Key Takeaways

  • Role: legacy bind/trigger for viewport resize on window.
  • Migrate: $(window).on("resize", fn) — preferred since 3.3.
  • Trigger: use .trigger("resize") instead of no-arg .resize().
  • Debounce: expensive work should wait until resizing pauses.

One line: .resize() is deprecated sugar for .on("resize") / .trigger("resize") on window.

Frequently Asked Questions

The .resize() method has two roles. With a handler — .resize(handler) or .resize(eventData, handler) — it binds a function that runs when the browser viewport changes size. Bind on $(window). With no arguments — .resize() — it triggers the resize event. Both forms exist since jQuery 1.0; binding is deprecated since 3.3.
Deprecated, not removed. Binding signatures are deprecated since jQuery 3.3 — use .on("resize", handler) instead. Unlike .error(), which was removed in jQuery 3.0, .resize() still works in jQuery 3.x. Prefer .trigger("resize") over no-arg .resize() for clarity.
.resize(handler) registers a callback and does not fire immediately. .resize() with no arguments triggers the resize event on each matched element — the same as .trigger("resize"). Always bind on $(window) for viewport size changes.
Replace .resize(fn) with .on("resize", fn). Replace .resize(data, fn) with .on("resize", data, fn). Replace no-arg .resize() with .trigger("resize"). Cleanup with .off("resize"). Under the hood, .resize(handler) already delegates to .on("resize").
Yes. jQuery 3.x keeps .resize() for backward compatibility. Docs mark it deprecated since 3.3 to steer new projects toward .on() and .trigger(). Prefer the modern API in the jQuery resize event tutorial.
Yes. Browsers may fire resize continuously while the user drags a window edge. Wrap expensive layout work in debounce or throttle, whether you use legacy .resize(fn) or modern .on("resize", fn).

Next: scroll event

Learn how to listen for scroll with .on("scroll").

scroll event 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.

8 people found this page helpful