Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

row.offsetHeight of a table row different in FireFox?

Posted on 2007-03-28
2
Medium Priority
?
580 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 29

Accepted Solution

by:
Pravin Asar earned 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

704 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