jQuery .resize() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Browser Events

Definition

.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").

Syntax

Start with these common calls. Keep them short and readable.

jQuery
// 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");
CallWhat it does
windowStandard target for viewport resize
handlerfunction(event)
eventDataExtra data as event.data
DebounceLimit how often expensive work runs

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

Parameters

ParameterDescription
Step 1Bind with $(window).resize(handler) (legacy) or .on("resize", handler) (preferred).
Step 2Optionally pass eventData: .resize(data, handler) → .on("resize", data, handler).
Step 3Trigger with no-arg .resize() (legacy) or .trigger("resize") (preferred).

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.

jQuery Examples

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.

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().

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.

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 →

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.

8 people found this page helpful