Solved

row.offsetHeight of a table row different in FireFox?

Posted on 2007-03-28
2
570 Views
Last Modified: 2013-11-19
In the following code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<style>
tr
{
    background-color:red;
    font-size:10pt;
}
</style>
<script language="javascript">
function onLoad()
{
    var div=document.getElementById("divCont");
   
    /*****************************/
    var NumOfRows = 1;
    /*****************************/
   
    var s = new Array();
    s.push("<table border=1 cellspacing=0 cellpadding=0>");
    for(var i=0; i<NumOfRows; i++)
    {
      s.push("<tr id='row_" + i + "'>");
      s.push("  <td>Row " + i);
      s.push("  </td>");
      s.push("<tr>");
    }
    s.push("</table>");
    div.innerHTML = s.join("\n");
   
    var row = document.getElementById("row_0");
    NumOfRows = (div.offsetHeight / row.offsetHeight);
   
    var s = new Array();
    s.push("<table border=1>");
    for(var i=0; i<NumOfRows; i++)
    {
      s.push("<tr id='row_" + i + "'>");
      s.push("  <td>Row " + i);
      s.push("  </td>");
      s.push("<tr>");
    }
    s.push("</table>");
    div.innerHTML = s.join("\n");
}
</script>
</head>
<body onload="onLoad();">
<div id="divCont" style="position:absolute;left:10px;top:10px;width:400px;height:200px;border:solid 1px blue;">
</div>
</body>
</html>

I've create a table with the number of rows depending on the height of the "divCont".
In IE and Opera it works perfectly and the table keeps inside the div exactly, but in FireFox the rows overflow the div.

What can be happening and how can I fix it for FireFox?

Thanks
0
Comment
Question by:mak730
2 Comments
 
LVL 36

Expert Comment

by:Zyloch
ID: 18812811
First of all, when you grab the height of the row, I would recommend getting the entire height of the table, especially since you add borders to the table. Thus, set an ID on the table and use getElementById() on that instead of row_0.

To fix for Firefox, make sure to set cellpadding and cellspacing in your second table to zero as well.
0
 
LVL 28

Accepted Solution

by:
Pravin Asar earned 500 total points
ID: 18815438
No points necessary.........



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<style>
tr
{
    background-color:red;
    font-size:10pt;
}
</style>
<script language="javascript">
function onLoad()
{
    var div=document.getElementById("divCont");
   
    /*****************************/
    var NumOfRows = 1;
    /*****************************/
   
    var s = new Array();
    s.push("<table border=1 cellspacing=0 cellpadding=0>");
    for(var i=0; i<NumOfRows; i++)
    {
      s.push("<tr id='row_" + i + "'>");
      s.push("  <td>Row " + i);
      s.push("  </td>");
      s.push("<tr>");
    }
    s.push("</table>");
    div.innerHTML = s.join("\n");
   
    var row = document.getElementById("row_0");
    NumOfRows = parseInt (parseInt(div.offsetHeight) / parseInt(row.offsetHeight));
   
    var s = new Array();

    ////////// TAKE CARE HERE...

    s.push("<table border=1 border=1 cellspacing=0 cellpadding=0>");
    for(var i=0; i<NumOfRows; i++)
    {
      s.push("<tr id='row_" + i + "'>");
      s.push("  <td>Row " + i);
      s.push("  </td>");
      s.push("<tr>");
    }
    s.push("</table>");
    div.innerHTML = s.join("\n");
}
</script>
</head>
<body onload="onLoad();">
<div id="divCont" style="position:absolute;left:10px;top:10px; width:auto; height:200px; border:solid 1px blue;">
</div>
</body>
</html>
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now