0

I have the following code and instead of height(300), height() = document height-100

$(".bar").height(XXX);
3
  • @GraceShao where XXX is I would like the document height-100px so .bar is slightly shorter then the page Jun 28, 2012 at 23:37
  • Read the docs, it tells you want to use api.jquery.com/height Jun 28, 2012 at 23:38
  • Note that jQuery height() only applies to the element height not taking into account, padding, borders or margins. Only mentioning it just in case you thought it would be the total height of the element including padding, borders and margins.
    – Nope
    Jun 28, 2012 at 23:58

2 Answers 2

3
var DocHeight = $(document).height();
$(".bar").height(DocHeight-100);
1

Try this:

var h = $(window).height() - 100;
$(".bar").height(h);
1
  • 1
    $(window).height() will get the height of the viewport. If you want the height of the actual HTML document and not the viewport you can use $(document).height() instead.
    – Nope
    Jun 29, 2012 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.