onresize Event

Example

Call a function when the browser window is resized:

<body onresize="myFunction()">
Try it Yourself »

More "Try it Yourself" examples below.


Description

The onresize event occurs when the browser window has been resized.

Tip: To get the size of an element, use the clientWidth, clientHeight, innerWidth, innerHeight, outerWidth, outerHeight, offsetWidth and/or offsetHeight properties.


Browser Support

Event
onresize Yes Yes Yes Yes Yes


Syntax

In HTML:

<element onresize="myScript">
Try it Yourself »

In JavaScript:

object.onresize = function(){myScript};
Try it Yourself »

In JavaScript, using the addEventListener() method:

object.addEventListener("resize", myScript);
Try it Yourself »

Technical Details

Bubbles: No
Cancelable: No
Event type: UiEvent if generated from a user interface, Event otherwise
HTML tags: <body>
DOM Version: Level 2 Events

More Examples

Example

Using the addEventListener() method to attach the "resize" event on the window object.

window.addEventListener("resize", myFunction);
Try it Yourself »

Copyright 1999-2023 by Refsnes Data. All Rights Reserved.