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
Call
What it does
Resize
Learn jQuery resize: bind $(window).on(\
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Attach with $(window).on("resize", handler).
Step 2
Read size with $(window).width() / .height() inside the handler.
Step 3
Debounce or throttle layout recalculation and DOM-heavy work.
Return Value
Return Value
Description
jQuery object
Most 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. ");
});
Many raw resize events during a drag
recalcLayout runs once ~200ms after the last event
Page stays smoother
How It Works
Raw events. Resize can fire many times during a drag.
Reset timer. Each event clears the previous timeout.
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.