Window Resize in jQuery

Question:

Create a web page which has a function to calculate whenever the window gets resized. When the user resizes the webpage,the count will be increased automatically. Display the total number of times that the user resize the page.

Refer the Sample Webpage below

Quiz for Exam - Window Resize in jQuery

Use 2 paragraph tags to display the output

  • First <p> tag with id “resize”
  • For Second <p> tag use id as ” test “

Include the JQuery Library – https://code.jquery.com/jquery-1.10.2.js

Code:

window.html

<!DOCTYPE html>
<html>
    <head>
        <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
        <script type="text/javascript">
            $(document).ready(function()
            {
                var x = 0;
                $(window).resize(function()
                {
                    $("span").text(x += 1);
                    
                });
                
            });
        </script>
    </head>
    <body>
        <p id="resize">
            Window resized
            <span>0</span> times.</p>
        <p id="test">Try resizing your browser window.</p>
    </body>
</html>

Recommended:

Leave a Comment

Your email address will not be published. Required fields are marked *