Categories
JavaScript Answers

What’s the equivalent of jQuery $(window).on(‘resize’) in JavaScript?

Spread the love

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', () => {})

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *