Div Full Width/Height of viewport with jQuery

[javascript]
// global vars
var winWidth = $(window).width();
var winHeight = $(window).height();

// set initial div height / width
$(‘div’).css({
‘width’: winWidth,
‘height’: winHeight,
});

// make sure div stays full width/height on resize
$(window).resize(function(){
$(‘div’).css({
‘width’: winWidth,
‘height’: winHeight,
});
});
[/javascript]

One Reply to Div Full Width/Height of viewport with jQuery

  1. Karthikeyan says:

    Try this one without any confusion…

    $(document).ready(function() {
    getWidthAndHeight();
    });
    // make sure div stays full width/height on resize
    $(window).resize(function() {
    getWidthAndHeight();
    });
    function getWidthAndHeight (){
    var winWidth = $(window).width();
    var winHeight = $(window).height();
    $(‘div#wrap’).css({‘width’: winWidth,’height’: winHeight,});
    }

Leave a Reply