

WidthOutput.textContent = window.innerWidth HeightOutput.textContent = window.innerHeight Window width: const heightOutput = document.querySelector('#height') Ĭonst widthOutput = document.querySelector('#width') Resize the browser window to fire the resize event. Bear in mind that since the example is running in an, you'll need to actually get the to resize before you see an effect. The following example reports the window size each time it is resized. See Resize Observer to read the draft document, and GitHub issues to read the on-going discussions.

There is a proposal to allow all elements to be notified of resize changes. Only handlers registered on the window object will receive resize events.

However, resize events are only fired on the window object (i.e. It is still possible to set onresize attributes or use addEventListener() to set a handler on any element. In some earlier browsers it was possible to register resize event handlers on any HTML element. The resize event fires when the document view (window) has been resized.
