jQuery | resize() with Examples

The resize() method is an inbuilt method in jQuery which is used when the browser window change its size.

Syntax:

$(selector).resize(function)

Parameter: This method accepts single parameter function which is optional. It is used to specify the function to run when the resize event is called.



Return Value: This method returns the selected element with increases its size.

Below example illustrates the resize() method in jQuery:

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head>
        <title>The resize method</title>
        <script src=
        </script>
          
        <!-- jQuery code to show the working of this method -->
        <script>
            x = 0;
            $(document).ready(function() {
                $(window).resize(function() {
                    $("p").text(x += 1);
                });
            });
        </script>
        <style>
            div {
                width: 150px;
                height: 100px;
                padding: 20px;
                border: 2px solid green;
                font-size: 20px;
            }
        </style>
    </head>
       
    <body>
        <div>
            <!-- press "ctrl" and "+" key together
            and see the effect -->
            Welcome to GfG!
            <br>
            <p>0</p>
            times.
        </div>
    </body>
</html>

chevron_right


Output:
Before click anything.

After clicking 2 times “ctrl” and “+” key together in keyboard.



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.