Home >>jQuery Tutorial >jQuery resize() Method

jQuery resize() Method

jQuery resize() Method

jQuery resize() method in jQuery is used to add a function or triggers the resize event to run the resize event occurs when the browser window changes size.

Syntax:

Trigger the resize event for the selected elements:

$(selector).resize()

Attach a function to the resize event:

$(selector).resize(function)

Parameter Values

Parameter Description
function It is an optional parameter and used to specifies the function to run when the resize event is triggered
Here is an Example of jQuery resize() Method:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
var x = 0;
$(document).ready(function(){
$(window).resize(function(){
$(".num").text(x += 1);
});
});
</script>
</head>
<body>
<p>Resized Window <span class="num">0</span> times.</p>
<p>Resizing your window size to see the effect</p>
</body>
</html>

Output:

Resized Window 0 times.

Resizing your window size to see the effect


No Sidebar ads