SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2004
    Location
    Texas
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Height of Divs - getting and setting

    Hello,

    I'm trying to get three side-by-side (floated) divs to be the same height, as if they were three cells in a table row.

    The only problem is getting and setting the height. The following code works in IE and Opera, but not Firefox. I tried .style.height, but that didn't seem to work for any browser.

    So: How do I get the height of a div in all browsers?

    Code:
    function boxFix()
    {
      var classId = document.all ? 'className' : 'class'
      var boxes = new Array()
      var k = 0
    
      var divs = document.getElementsByTagName('div')
    
      for( i=0; i<divs.length; i++)
        if( divs[i].getAttribute( classId ) == "box" )
          boxes[k++] = divs[i]
    
      var max = findMax( boxes )
      
      for( i = 0; i < boxes.length; i++ )
        boxes[i].style.height = max
    }
    
    function findMax( arr )
    {
      var max = arr[0].offsetHeight
      for( i = 0; i < arr.length; i++ )
      {
        if( arr[i].offsetHeight > max )
          max = arr[i].offsetHeight
      }
      return max
    }
    Thank very much in advance!

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2004
    Location
    Texas
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow... thanks.

    By the way, is it just personal preference when people write "Javascript", "_Javascript", or "java_script_"?

  4. #4
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The forum software added the under-scores. It's a security thing ;-)

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2004
    Location
    Texas
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Got it working... Thanks for the help!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •