Setting the height of two elements to match each other
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Setting the height of two elements to match each other

From: Andy Jeffries <news@andyjeffries.co.uk>
Date: Mon Sep 26 2005 - 15:13:00 CEST

Hi all,

I want to write a function that given two elements will make their
heights equal to the larger element. I've had a go at it and it works,
but it makes both their heights larger than either of them (but equal)

The code is as follows:

var newheight = (second.offsetHeight > first.offsetHeight) ?
        second.offsetHeight :
        first.offsetHeight;
        
first.style.height = newheight + "px";
second.style.height = newheight + "px";

So, I'm obviously doing something stupid, but can anyone enlighten me?
I tried writing to offsetHeight but the changes seemed to be ignored.

Cheers,

Andy
Received on Tue Oct 18 03:30:14 2005