Wednesday, November 5, 2008

Setting the height of a Div in Javascript works in Internet Explorer but not in Firefox

If you notice this in you program, you're probably giving the height as an integer instead of in units.
For example:


function SetHeights() {
divMain = getElementsById("Main");
divWrapper = getElementsById("Wrapper");
divHeaderWrap = getElementsById("HeaderWrap");
divFooter = getElementsById("Footer");
divMain.style.height = Math.max(divWrapper.offsetHeight - (divFooter.offsetHeight + divHeaderWrap.offsetHeight + 18), 0);
}


You should set the height in pixels or em etc.:


function SetHeights() {
divMain = getElementsById("Main");
divWrapper = getElementsById("Wrapper");
divHeaderWrap = getElementsById("HeaderWrap");
divFooter = getElementsById("Footer");
divMain.style.height = Math.max(divWrapper.offsetHeight - (divFooter.offsetHeight + divHeaderWrap.offsetHeight + 18), 0)+"px";
}

No comments: