Solved

row.offsetHeight of a table row different in FireFox?

Posted on 2007-03-28
2
568 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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Tag input html 4 35
listing all functions in JavaScript 19 96
jQuery Time Off Event 20 41
Java Server Faces parameter pass? 6 18
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

763 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

11 Experts available now in Live!

Get 1:1 Help Now