Set div height to window height jquery


Source Code:

  • code
  • source
  1. <script>
  2. // get window height and width
  3. var winWidth = $(window).width();
  4. var winHeight = $(window).height();
  5. // set div height and width
  6. $('div').css({
  7. 'width': winWidth,
  8. 'height': winHeight,
  9. });
  10. // update height and width on window resize
  11. $(window).resize(function(){
  12. $('div').css({
  13. 'width': winWidth,
  14. 'height': winHeight,
  15. });
  16. });
  17. </script>
<script>
// get window height and width
var winWidth = $(window).width();
var winHeight = $(window).height();

// set div height and width
$('div').css({
    'width': winWidth,
    'height': winHeight,
});

// update height and width on window resize
$(window).resize(function(){
    $('div').css({
        'width': winWidth,
        'height': winHeight,
    });
});
</script>

Reviews and Comments