jQuery .resize() Method

Beginner
⚠️ Deprecated since 3.3
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Browser events

What You’ll Learn

The .resize() method is jQuery’s legacy shorthand for binding and triggering the resize event on the window. This tutorial covers .resize(handler) since 1.0, .resize(eventData, handler) since 1.4.3, no-argument .resize() as a trigger, migration to .on("resize") and .trigger("resize"), and why the binding form is deprecated since jQuery 3.3 but still works in 3.x. See the jQuery resize event tutorial for the modern API.

01

.resize(fn)

Bind handler

02

eventData

Since 1.4.3

03

.resize()

Trigger event

04

.on()

Modern bind

05

.trigger()

Modern fire

06

Deprecated

Since 3.3

Introduction

Before jQuery 1.7 unified events with .on() and .off(), every common event had a matching shorthand — .resize(), .scroll(), .click(), and more. The .resize() method let you react to viewport changes in one short call: $(window).resize(function(){ layout(); }). It remains in jQuery 3.x for backward compatibility but is marked deprecated since 3.3 — unlike .error(), which was removed in jQuery 3.0.

Understanding .resize() matters when reading older dashboard, chart, and responsive-layout tutorials in legacy codebases. The method does two distinct jobs: with a function argument it binds; with no arguments it triggers. Modern jQuery splits those roles explicitly — .on("resize", handler) for binding and .trigger("resize") for firing.

⚠️
Bind on $(window)

The official jQuery API sends the resize event to the window when the browser viewport changes. Use $(window).resize(handler) or $(window).on("resize", handler) — not $(document) or $("body") — for consistent cross-browser viewport handling. Never rely on how many times resize fires; debounce expensive layout work.

Understanding the .resize() Method

The official jQuery API describes .resize() as a way to bind an event handler to the resize event, or trigger that event on an element. When you pass a handler, jQuery registers it on each matched element and calls it when the browser window size changes — the same resize event that .on("resize") handles today. In practice, bind on $(window) for viewport changes.

When you call .resize() with no arguments, jQuery synthetically fires the resize event on each matched element. Bound handlers run once per call. This trigger behavior is equivalent to .trigger("resize").

⚠️
Deprecated since jQuery 3.3

Do not use .resize(handler) or .resize(eventData, handler) in new code. Replace them with .on("resize", handler) or .on("resize", eventData, handler). Replace no-argument .resize() with .trigger("resize"). Unlike .error() (removed in 3.0), .resize() still works in jQuery 3.x. For debouncing, breakpoints, and the full modern resize workflow, read the jQuery resize event tutorial.

📝 Syntax

The .resize() method has three signatures from the official jQuery API. The binding forms are deprecated; the trigger form remains valid but .trigger("resize") is preferred:

1. Bind a handler — .resize( handler ) (since 1.0, deprecated 3.3)

jQuery
.resize( handler )
  • handler — function executed each time resize fires: function( event ) { ... }.
  • Returns the jQuery object for chaining.
  • Bind on $(window) for viewport size changes.
  • Modern replacement: .on( "resize", handler ).

2. Bind with eventData — .resize( [eventData], handler ) (since 1.4.3, deprecated 3.3)

jQuery
.resize( [eventData], handler )
  • eventData — optional object available in the handler as event.data.
  • Modern replacement: .on( "resize", eventData, handler ).

3. Trigger the event — .resize() (since 1.0)

jQuery
.resize()
  • No arguments — triggers resize on every matched element.
  • Runs bound resize handlers.
  • Preferred replacement: .trigger( "resize" ).

Official jQuery API migration note

jQuery
// Deprecated binding
$( window ).resize( function() {
  alert( "Handler for `resize` called." );
} );

// Modern binding
$( window ).on( "resize", function() {
  alert( "Handler for `resize` called." );
} );

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

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

Return value

  • All .resize() signatures return the original jQuery object for chaining.
  • Handler return values are ignored unless you use return false (equivalent to preventDefault() + stopPropagation()).

⚡ Quick Reference

GoalLegacy (.resize)Modern replacement
Bind resize handler on window$(window).resize(fn)$(window).on("resize", fn)
Pass data to handler$(window).resize({ breakpoint: 480 }, fn)$(window).on("resize", { breakpoint: 480 }, fn)
Trigger resize programmatically$(window).resize()$(window).trigger("resize")
Read viewport width$(window).width() inside the handler
Remove resize handlers$(window).off("resize")$(window).off("resize")
Debounced layout recalcWrap body in setTimeout / clearTimeout — never assume call count
Delegated resizeNot applicable — bind on $(window) only for viewport changes

📋 .resize() vs .on("resize") vs .trigger("resize") vs .off("resize")

Four related APIs — know which one binds, which one fires, and which one removes handlers.

.resize()
deprecated

Legacy bind (.resize(fn)) or trigger (.resize()) on $(window) — use modern APIs for new code

.on("resize")
bind

Modern binding since 1.7 — supports eventData; preferred for viewport layout code

.trigger("resize")
fire

Programmatically run handlers — clearer than no-arg .resize()

.off("resize")
remove

Unbind handlers — pair with .on("resize") when cleaning up or in SPAs

Examples Gallery

Five examples cover binding on $(window), eventData breakpoints, triggering, migration from .resize() to .on("resize"), and debouncing inside a legacy handler. Use the Try-it links to run each snippet in the browser. Remember: binding with .resize(handler) is deprecated — these demos show legacy syntax you will encounter in older code.

📚 Binding & Triggering

Legacy .resize() signatures for binding handlers on the window and firing events programmatically.

Example 1 — Bind Handler with .resize(handler) on $(window)

The canonical legacy pattern — append to a log when the browser window resizes.

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

How It Works

$(window).resize(fn) registers the function on the window object. jQuery internally routes this to .on("resize", fn). The handler runs each time the viewport size changes.

Example 2 — Pass eventData with .resize(eventData, handler)

Since jQuery 1.4.3, pass a breakpoint before the handler — it arrives as event.data.

jQuery
function apply( bp ) {
  var w = $( window ).width();
  $( "body" ).toggleClass( "is-narrow", w < bp ).toggleClass( "is-wide", w >= bp );
  $( "#status" ).text( w < bp ? "Narrow (< " + bp + "px)" : "Wide (≥ " + bp + "px)" );
}

$( window ).resize( { breakpoint: 480 }, function( e ) {
  apply( e.data.breakpoint );
} );
apply( 480 );
Try It Yourself

How It Works

jQuery stores the { breakpoint: 480 } object and injects it into event.data when resize fires. The apply() helper toggles CSS classes based on viewport width. Modern equivalent: .on("resize", { breakpoint: 480 }, fn).

Example 3 — Trigger Resize with No-Argument .resize()

Calling .resize() without a handler fires the resize event programmatically — bound handlers run once per call.

jQuery
var count = 0;

$( window ).resize( function() {
  count++;
  $( "#log" ).text(
    "Handler called " + count + " time(s). Width: " + $( window ).width() + "px"
  );
} );

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

How It Works

The first .resize(function(){ ... }) binds a handler on $(window). The button calls $(window).resize() with no arguments — that synthetically fires resize. Replace with $(window).trigger("resize") for clarity.

📈 Migration & Debouncing

Compare legacy and modern APIs, and debounce expensive work inside .resize(handler).

Example 4 — Migration: .resize(fn) vs .on("resize", fn)

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

jQuery
// Modern (recommended)
$( window ).on( "resize", function() {
  $( "#log" ).append(
    "<div>.on('resize') handler — width " + $( window ).width() + "px</div>"
  );
} );

// Legacy (deprecated): $( window ).resize( function() { ... } );

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

How It Works

Under the hood, .resize(fn) calls .on("resize", fn). Migration is a straight rename with no behavior change for simple window bindings. The button uses .trigger("resize") — the modern replacement for no-arg .resize().

Example 5 — Debounced Legacy .resize(handler)

Never rely on how many times resize fires — debounce layout recalculation inside the handler.

jQuery
var raw = 0, deb = 0, timer;

$( window ).resize( function() {
  raw++;
  $( "#raw" ).text( raw );
  clearTimeout( timer );
  timer = setTimeout( function() {
    deb++;
    $( "#deb" ).text( deb );
    $( "#box" ).text(
      "Width: " + $( window ).width() + "px — layout #" + deb
    );
  }, 200 );
} );
Try It Yourself

How It Works

Every resize event increments the raw counter immediately. The debounced block waits 200ms after the last resize before updating layout — so expensive DOM work runs once per resize burst, not on every intermediate pixel. Apply the same pattern when you migrate to .on("resize", fn).

🚀 Common Use Cases

  • Reading legacy code — recognize $(window).resize(fn) as equivalent to .on("resize", fn) in older dashboard scripts.
  • Responsive layout toggles — legacy tutorials bind .resize() to switch mobile/desktop CSS classes at breakpoints.
  • Programmatic trigger$(window).resize() from a button — replace with .trigger("resize").
  • Shared eventData$(window).resize({ breakpoint: 768 }, fn) passes metadata without closures.
  • Chart and canvas redraws — debounced .resize(fn) calls in older visualization libraries.
  • Maintaining legacy admin UIs — many jQuery 1.x panels still use .resize() — know how to migrate safely to jQuery 3.x.

🧠 How .resize() Routes Through jQuery

1

You call .resize()

With a function argument, jQuery treats it as a bind request. With no arguments, it treats it as a trigger request. Bind on $(window) for viewport changes.

dispatch
2

Bind path

.resize(handler) delegates internally to .on("resize", handler) — the handler is stored in jQuery’s event system on the matched element (typically window).

.on("resize")
3

Trigger path

No-arg .resize() delegates to .trigger("resize") — bound handlers run when resize fires, without a real viewport change.

.trigger("resize")
4

jQuery object returned

Both paths return the original collection for chaining — debounce inside the handler because browsers may fire resize many times per second during a drag.

📝 Notes

  • Deprecated since jQuery 3.3 — do not use .resize(handler) or .resize(eventData, handler) in new code. Use .on("resize") instead. Unlike .error(), .resize() is not removed in jQuery 3.x.
  • Bind with .resize(handler) since jQuery 1.0; eventData form since 1.4.3.
  • No-argument .resize() triggers the event since jQuery 1.0 — prefer .trigger("resize").
  • Always bind on $(window) for viewport size changes — not document or body.
  • Never rely on a specific resize call count — browsers fire continuously while dragging in some engines.
  • Debounce or throttle expensive layout, chart, and measurement code inside handlers.
  • Remove handlers with .off("resize") — not by calling .resize(undefined).
  • For the full modern resize guide — debouncing, breakpoints, and .trigger("resize") — see the jQuery resize event tutorial.

Browser Support

The underlying resize event fires on the window when the viewport changes in browsers jQuery targets. The .resize() method itself is a jQuery API — it works in jQuery 1.x, 2.x, and 3.x. Binding via .resize(handler) is deprecated since 3.3 but still functional; triggering via no-arg .resize() also remains supported.

jQuery 1.0+

jQuery .resize() method

Supported across all jQuery versions you are likely to maintain. Deprecated binding since 3.3 — use .on('resize') for new projects. Unlike .error() (removed in 3.0), .resize() still works in jQuery 3.x. Native equivalent for binding: window.addEventListener('resize', fn). Native equivalent for trigger: .trigger('resize') or dispatchEvent.

100% With jQuery loaded
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 responsive layout and dashboard code. Always debounce expensive handlers.

Conclusion

The jQuery .resize() method is the legacy shorthand for binding and triggering resize handlers on the window. Use .resize(handler) or .resize(eventData, handler) to bind — both deprecated since jQuery 3.3. Use no-argument .resize() to trigger — equivalent to .trigger("resize"). Unlike .error(), it still works in jQuery 3.x.

For new code, prefer .on("resize", fn) for binding and .trigger("resize") for programmatic firing. Bind on $(window), debounce expensive work, and never rely on call count. When you encounter .resize() in older dashboard and chart scripts, recognize it, understand it, and migrate when practical. For debouncing, breakpoints, and the complete modern resize workflow, continue with the jQuery resize event tutorial.

💡 Best Practices

✅ Do

  • Use .on("resize", handler) for all new resize bindings on $(window)
  • Use .trigger("resize") instead of no-arg .resize()
  • Debounce or throttle expensive layout recalculation inside handlers
  • Migrate .resize(fn) to .on("resize", fn) when refactoring legacy files
  • Read the modern resize event tutorial for breakpoints and chart redraw patterns

❌ Don’t

  • Write new viewport handlers with deprecated .resize(handler)
  • Bind resize on document or body instead of $(window)
  • Assume resize fires a predictable number of times during a drag
  • Confuse .resize(fn) (bind) with .resize() (trigger)
  • Confuse window resize with scroll or orientationchange
  • Copy deprecated patterns from old tutorials without modernizing them

Key Takeaways

Knowledge Unlocked

Six things to remember about .resize()

Legacy bind, modern migrate.

6
Core concepts
data 02

eventData

Since 1.4.3

Handler
() 03

.resize()

Trigger

No args
.on 04

.on("resize")

Modern

Replace
05

.trigger()

Fire

Programmatic
3.3 06

Deprecated

Since 3.3

Not removed

❓ Frequently Asked Questions

The .resize() method has two roles. With a handler argument — .resize(handler) or .resize(eventData, handler) — it binds a function that runs when the browser window viewport changes size. Bind on $(window) for viewport changes. With no arguments — .resize() — it triggers the resize event on each matched element, running bound handlers. Both forms have been part of jQuery since 1.0; the binding form is deprecated since 3.3.
Deprecated, not removed. The binding signatures .resize(handler) and .resize(eventData, handler) are deprecated since jQuery 3.3 — use .on('resize', handler) instead. Unlike .error(), which was removed entirely in jQuery 3.0, .resize() still works in jQuery 3.x for backward compatibility. The no-argument .resize() trigger form also remains supported, though .trigger('resize') is clearer.
.resize(handler) registers a callback — it does not fire the event immediately. .resize() with no arguments triggers the resize event programmatically on every matched element, the same as .trigger('resize'). The handler form is deprecated for binding; the no-arg form is a trigger shorthand. Always bind on $(window) when reacting to 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'). Replace .unbind('resize') cleanup with .off('resize'). Under the hood, .resize(handler) already delegates to .on('resize') — migration is a straight rename with no behavior change for simple window bindings.
Yes. jQuery 3.x keeps .resize() for backward compatibility. It still binds and triggers correctly on $(window). The API docs mark it deprecated since 3.3 to steer new projects toward .on() and .trigger(). Do not use .resize(handler) in new code — prefer the modern API in the jQuery resize event tutorial.
Yes. Browsers may fire resize continuously while the user drags a window edge — never rely on a specific call count. Wrap expensive layout recalculation, chart redraws, and DOM measurements in debounce or throttle inside your handler, whether you use legacy .resize(fn) or modern .on('resize', fn). Example 5 on this page demonstrates debouncing inside a legacy .resize() handler.
Did you know?

jQuery event shorthands like .resize(handler) were thin wrappers around .bind("resize", handler) before .on() unified the API in jQuery 1.7. When you call .resize(fn) today, jQuery still routes through the same event system as .on("resize", fn) — which is why migration is a rename with no behavior change for simple window bindings. jQuery removed .error() in 3.0 but kept .resize() as deprecated — a softer fate for viewport layout code still common in legacy dashboards.

Next: jQuery Scroll Event

Detect scrolling on $(window) and overflow elements — build progress bars and lazy-load triggers.

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.

6 people found this page helpful