X

LATEST #JQUERY NEWS

Using jQuery’s .resize() Method


jQuery’s .resize() method is a cool way to have an event triggered or have a function executed when something is resized. For the purposes of this tutorial, we’re going to show you how to use the .resize() method to trigger an alert method whenever the window is resized. You might be surprised at how easy this functionality is to add to any of your code.

In terms of syntax, the .resize() method is used in much the same was as any other jQuery method. Take a look at the snippet below to get a look for yourself:

$(window).resize(function(){
alert(“The window has been resized!”);
})

That’s all it takes to use the resize method to trigger an alert message once the window has been resized. Feel free to use the code and change the alert message to say whatever you like. Just be aware that if you are going to use this code, the alert messages that will appear will likely be very annoying for the user, as an alert will pop up whenever the window changes size, even if it happens in one fluid motion. Making the window 50px less wide will send 50 alert messages. Still, the concept behind the .resize() method is pretty neat, and a lot of different functionalities can be achieved by using it.

Recently Published

article image
»

jQuery Snippets: How to Add/Remove Classes After Delay

In your projects, there can often be instances of wanting to change ...

article image
»

jQuery Snippets: Back to Top Button

One common way to use jQuery is to add a useful and functional ...

article image
»

jQuery .on() Method: the Issue of Dynamically Added Elements

The jQuery .on() method is the recommended way for attaching events ...

article image
»

How to Use jQuery to Test CSS3 Browser Support

The tricky thing about using CSS properties (especially newer ones ...

article image
»

jQuery Snippets: Check/Un-Check All Function

This easy-to-implement jQuery code snippet is super useful, and can ...

article image
»

Useful jQuery Code Snippets for Handling CSS

If you’re not already familiar with code snippets, they are ...

article image
»

Using Method Chaining in jQuery

Using method chaining in jQuery helps to ensure that your code stays ...

article image
»

jQuery’s .children() Method

Just like in CSS, it’s possible to use jQuery to select the ...

article image
»

jQuery’s .click() Method

With jQuery, it’s super easy to make something happen as a result ...