jQuery resize Event

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

Definition

The resize event is sent to the window when the browser viewport changes size. Bind it with $(window).on("resize", handler) (since jQuery 1.7). Trigger it with .trigger("resize").

Syntax

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

jQuery
$(window).on("resize", function () {
  // viewport size changed
});

$(window).trigger("resize"); // fire handlers programmatically

// Do not rely on how many times the handler runs
// Debounce expensive layout / chart work
CallWhat it does
ResizeLearn jQuery resize: bind $(window).on(\

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

Parameters

ParameterDescription
Step 1Attach with $(window).on("resize", handler).
Step 2Read size with $(window).width() / .height() inside the handler.
Step 3Debounce or throttle layout recalculation and DOM-heavy work.

Return Value

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

jQuery Examples

Example 1 — Append to #log

Official pattern: append a short message each time resize fires.

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

How It Works

  1. Bind. .on("resize") on window listens for viewport changes.
  2. Resize. The browser fires the event when the window size changes.
  3. Append. Each firing adds another message fragment.

Example 2 — Show Window Width

Official demo: prepend the current $(window).width() on each resize.

jQuery
$(window).on("resize", function () {
  $("body").prepend($(window).width() + " ");
});
Try It Yourself

How It Works

  1. Listen. The handler runs on every resize event.
  2. Measure. $(window).width() reads the current viewport width.
  3. Prepend. New values are inserted at the top of body.

Example 3 — Debounce Expensive Work

Wait until resizing pauses before recalculating layout.

jQuery
var timer;

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

$(window).on("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.

Frequently Asked Questions

The resize event is sent to the window element when the browser viewport changes size — for example when the user drags a window edge or rotates a device. Bind with $(window).on("resize", handler) since jQuery 1.7. Use it to recalculate layouts, update charts, or sync UI to the current viewport width and height.
The official jQuery API sends resize to the window object when the browser window size changes. $(window).on("resize", fn) is the standard pattern. Binding on document or body may not receive the native event consistently. Always target window for viewport resize handling.
Browser behavior varies. In Internet Explorer and WebKit, resize may fire continuously while the user drags. In some other browsers it may fire only once when resizing finishes. Never rely on a specific call count — debounce or throttle expensive work instead.
Yes, for anything heavier than a simple log line. Because resize can fire many times per second during a drag, layout recalculation, chart redraws, and DOM measurements should run through debounce or throttle so your page stays responsive.
Call $(window).trigger("resize"). Bound resize handlers on window run as if the viewport changed — useful when your code changes layout dimensions without the user resizing the browser.
The shorthand method .resize(handler) is deprecated as of jQuery 3.3 (it still works in 3.x). Prefer $(window).on("resize", handler) — the event API this page teaches. See the .resize() shorthand page for migration notes.

Next: .resize() Method

See the deprecated shorthand and how to migrate to .on("resize").

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

8 people found this page helpful