zeesh
08-14-2007, 01:58 AM
I would like my div container's height to automatically resize with the content that is added dynamically or dragged & dropped into it. I couldnt figure out the proper CSS without using fixed height and a scrollbar that I don't want. I tried using javascript to resize the container when new content is added to it but the scrollHeight always gets larger & larger even as I remove content. Here is my JS function, is there a better property I could use to determine:
1. If the content area of the div container is larger than the client window then resize the container to be the size of the content area else resize the container to be the size of the client window
function resize(){
var htmlheight = document.body.parentNode.scrollHeight;
var windowheight = document.body.parentNode.clientHeight;
var containerDiv = document.getElementById(containerId);
if ( htmlheight < windowheight ) {
containerDiv.style.height = windowheight + "px";
}
else {
containerDiv.style.height = htmlheight + "px";
}
}
1. If the content area of the div container is larger than the client window then resize the container to be the size of the content area else resize the container to be the size of the client window
function resize(){
var htmlheight = document.body.parentNode.scrollHeight;
var windowheight = document.body.parentNode.clientHeight;
var containerDiv = document.getElementById(containerId);
if ( htmlheight < windowheight ) {
containerDiv.style.height = windowheight + "px";
}
else {
containerDiv.style.height = htmlheight + "px";
}
}