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’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 ...

article image
»

Using jQuery’s .resize() Method

jQuery’s .resize() method is a cool way to have an event ...

article image
»

How to Use jQuery to Search and Replace HTML

Have you ever made a mistake in your code or in your text and dreaded ...

article image
»

How to Use jQuery’s .mouseover() Method

jQuery’s .mouseover() method is used to execute some jQuery ...

article image
»

How to Use jQuery’s .blur() Method

jQuery’s .blur() method isn’t exactly what it sounds like ...

article image
»

jQuery 3.0: Fix url.indexOf is Not a Function Error

jQuery 3.0 is out, and if you started working with it and plan to ...

article image
»

Set/Get/Delete Cookies with jQuery

There are a lot of plugins you can use to set, get, and delete ...

Screen Shot 2016-11-26 at 12.05.09 PM
»

3 Best jQuery Video Gallery Plugins

Do you have a lot of videos that you’d like to embed or neatly ...