How to use resize() function in jQuery ? Last Updated : 29 Jul, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we will learn about the resize() method which is an inbuilt method provided by jQuery. This method is used for binding an event listener to the resize event. This event is fired when the size of the browser window changes its size, either by the user or due to some other reason. This method can also be used to trigger the resize event on an element.Note that the event may not continuously fire when the resize is taking place and may only fire in the end, hence it is not recommended to depend on the events for an exact count.Syntax:$(selector).resize( handler )Parameter: This method accepts a single parameter function as mentioned above and described below:handler: This specifies the callback handler that will be called when the resize event occurs. An optional parameter can be passed in the callback function that contains the details of the event.The below example illustrates the resize() method in jQuery:Example 1: HTML <!DOCTYPE html> <html> <head> <!-- Enable to automatically set the width to device-width for preventing inconsistencies using the method --> <meta name="viewport" content= "width=device-width, initial-scale=1.0" /> <script src= "https://code.jquery.com/jquery-3.6.0.min.js"> </script> </head> <body> <h1 style="color: green;"> GeeksforGeeks </h1> <h3>Explain resize() function in jQuery?</h3> <p> Resize the window to get the new height and width </p> <p> <b>Current Window Height:</b> <span id="window-height"></span> </p> <p> <b>Current Window Width:</b> <span id="window-width"></span> </p> <script type="text/javascript"> $(window).resize((eventData) => { console.log("Page has been resized!"); // Get the event type from the // event data available to the // callback function console.log("Event Data type", eventData.type); // Update the values on the page $("#window-height").text($(window).height() + "px"); $("#window-width").text($(window).width() + "px"); }); </script> </body> </html> Output:Example 2: HTML <!DOCTYPE html> <html> <head> <script src= "https://code.jquery.com/jquery-3.6.0.min.js"> </script> </head> <body> <h1 style="color: green;"> GeeksforGeeks </h1> <h3>Explain resize() function in jQuery?</h3> <p>Resize the window to get a new font size</p> <p id="text"> Hello Geeks, this text will resize depending on the page size </p> <script type="text/javascript"> function resizeFont() { // Find the font size on the basis of // the current window width let fontSize = $(window).width() * 0.1; // Update the font size $("#text").css("font-size", fontSize + "px"); } resizeFont(); // Use the resize method with the above // function as the callback $(window).resize(resizeFont); </script> </body> </html> Output:Reference: https://api.jquery.com/resize/ Comment More infoAdvertise with us Next Article jQuery UI Resizable stop Events S sayantanm19 Follow Improve Article Tags : Web Technologies JQuery Geeks Premier League Geeks-Premier-League-2022 jQuery-Methods jQuery-Questions +1 More Similar Reads How to change font size using jQuery ? In this article, we will see how to change the font size of an element using jQuery. To change the font size of an element, we will use css() method. The css() method is used to change the style property of the selected element. Syntax: $(selector).css(property) Return value: It will return the valu 1 min read How to trigger the window resize event in jQuery ? To discuss how to trigger the window resize event using jQuery. For this purpose, we will use the following library functions provided by jQuery.$(<element>).trigger(): This library function allows us to trigger both native and customized events. The method can be used independently or can be 1 min read jQuery UI dialog resizeStop() Event jQuery UI resizeStop event is triggered when the dialog box is stopped after we resized. Syntax: $(".selector").dialog ( resizeStop: function( event, ui ) { console.log('resized') },Approach: First, add jQuery UI scripts needed for your project. <link href = "https://code.jquery.com/ui/1.10.4/the 1 min read jQuery UI Resizable stop Events jQuery UI is a web-based technology and consists of GUI widgets, visual effects, and themes implemented using the jQuery, JavaScript Library. jQuery UI is the best tool for building UI interfaces for the webpages. It can also be used to build highly interactive web applications or can be used to add 2 min read How to get font size of an element using jQuery ? In this article, we will see how to get the font size of an element using jQuery. To get the font size of an element, we will use css() method. The css() method is used to set or return the style property of the selected element. Syntax: var style = $(selector).css(property) Return value: This metho 2 min read How to create auto-resize textarea using JavaScript/jQuery ? Creating an auto-resize textarea using JavaScript or jQuery means dynamically adjusting the height of the textarea to fit its content as the user types. This enhances user experience by preventing the need for scrolling within the textarea, ensuring all content is visible.Table of ContentUsing JavaS 3 min read Like