jQuery window bind resize event

Description

jQuery window bind resize event

View in separate window

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Executing a Function on Resize Event in jQuery</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<style>
    p{/* w ww  .j av a  2  s  .  com*/
        padding: 20px;
        font: 20px sans-serif;
        background: #f0e68c;
    }
</style>
<script>
$(document).ready(function(){
    $(window).resize(function() {
        $(window).bind("resize", function(){
            $("p").text("Window width: " + 
                  $(window).width() + 
                  ", " + 
                  "Window height: " + 
                  $(window).height());
        });
    });
});
</script>
</head>
<body>
    <p>resize the browser window by dragging the corners.</p>
</body>
</html>



PreviousNext

Related