resize() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:resize

Description

The resize() method triggers the resize event, or sets function as resize event handler.

Syntax

$(selector).resize(function);
Parameter Require Description
function Optional.function to run when the resize event is triggered

The following code shows how to Count the number of times the browser window is resized:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
x = 0;//from  ww w . ja va  2 s. c  om
$(document).ready(function(){
    $(window).resize(function(){
        $("span").text(x += 1);
    });
});
</script>
</head>
<body>

<p>Window resized <span>0</span> times.</p>
<p>Try resizing your browser window.</p>

</body>
</html>

Related Tutorials