Sometimes, we want to find the equivalent of jQuery $(window).on('resize')
in JavaScript.
In this article, we’ll look at the equivalent of jQuery $(window).on('resize')
in JavaScript.
What’s the equivalent of jQuery $(window).on(‘resize’) in JavaScript?
The equivalent of jQuery $(window).on('resize')
in JavaScript is:
window.addEventListener('resize', () => {})
We call window.addEventListener
with 'resize'
and a callback that runs when the window is resized to add an event listener for the resize event.
The resize event is triggered when we resize the window.
Conclusion
The equivalent of jQuery $(window).on('resize')
in JavaScript is:
window.addEventListener('resize', () => {})