How to set the height of the div to vertical space of the browser
I have a div which should occupy the remaining vertic开发者_Python百科al space of the browser window. If the content in that div is maximum than the height of the div, it should add scroll bar for that div.
I'm tried something similar to this, but it is of no use
h = $(document).height();
$("#mydiv").attr(height : h);
Try this...
h = $(document).height();
$("#mydiv").css('height', h);
you need the window height :)
$(window).height()
like so:
$("#mydiv").height($(window).height());
You can use either $(window).height() or $(document).height() depending on which is interesting for you.
Height is not a DOM attribute, it is a CSS attribute. But it is nicely abstracted into the height() function so you can use it for setting aswell.
var height_to_set = $(document).height();
$("#mydiv").height(height_to_set);
精彩评论