Example

Count the number of times the browser window is resized:

$(window).resize(function() {
  $('span').text(x+=1);
});

Try it yourself »

Definition and Usage

The resize event occurs when the browser window changes size.

The resize() method triggers the resize event, or if the function parameter is set, it specifies what happens when a resize event occurs.


Trigger the resize Event

Trigger the resize event for the selected element.

Syntax

$(selector).click()
Try it yourself »


Bind a Function to the resize Event

Specifies a function to run when the resize event is triggered for the selected element.

Syntax

$(selector).resize(function)
Try it yourself »

Parameter Description
function Optional. Specifies the function to run when the resize event is triggered.