jQuery Event How to - Handle window resized event








Question

We would like to know how to handle window resized event.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.9.1.js'></script>
<!--   w w w.  j  a va  2s. com-->
<script type='text/javascript'>
$(window).load(function(){
    $(window).resize(function() { console.log('you resized the window!'); });
});
</script>
</head>
<body>
  <div id='testDiv'>HERE'S SOME TEXT</div>
</body>
</html>

The code above is rendered as follows: