tags:

views:

6642

answers:

3

Here the total height of all DIV'S are 900px, but the jqurey function returns the height of the body as 577px.(if i removed body css, its working). can any body have solution for this problem?

$j(function(){
 alert($j("body").height());
})


html,body{
 height:100%;
}


<div style="height:200px">header</div>
<div style="height:500px">content</div>
<div style="height:200px">footer</div>
+6  A: 

set

head { height: 100%; }
body { min-height: 100%; }

instead of height: 100%? The result jQuery returns is correct, because you've set the height of the body to 100% and that's probably the height of the viewport. These three DIVs were causing an overflow, because there weren't enough space for them in the BODY element. To see what I mean, set a border to the BODY tag and check where the border ends.

Rafael
+1 that's exactly what I was thinking
jsidnell
nice explanation Mr.Rafael thank you!
Srikanth
you're welcome, john
Rafael
While this may work for this case, this isn't an answer to the asked question. http://stackoverflow.com/questions/1304378/jquery-web-page-height
B T
A: 

I believe that the body height being returned is the visible height. If you need the total page height, you could wrap your div tags in a containing div and get the height of that.

Sohnee
+6  A: 

Simply use

$(document).height() // - $('body').offset().top

and / or

$(window).height()

instead $('body').height()

OderWat
this is also nice one Mr.OderWat, but i am getting 8px extra than that of actual size.(by using $(document).height() ).
Srikanth
Those 8 pixels "more" are correct. They are the margins of the document. You may either use: body { height:100%; margin:0 } or you substract the offset using $(document).height()-$("body").offset().top
OderWat
$("body").offset().top works for equal margins on body but if the bottom margin is set specifically, it won't work. Also, I tried $("body").css("margin-bottom") but that returns with the units and it may not always be in pixels. Are there any other ways to find out the "more"?
Jiho Han