Re: Dynamically Generated table does not apply styles



On Aug 8, 4:46 am, RobG <rg...@xxxxxxxxxxxx> wrote:
On Aug 8, 5:17 pm, David Mark <dmark.cins...@xxxxxxxxx> wrote:

On Aug 8, 2:57 am, Nikron <xml.mig...@xxxxxxxxx> wrote:
[...]
function BuildGrid(TargetDIV)
{
if (document.getElementById(TargetDIV))
{
var divTarget = document.getElementById(TargetDIV);

var tblGrid = document.createElement("table");
var tblBody = document.createElement("tbody");

// add the body to the grid
tblGrid.appendChild(tblBody);

Append the table to its container before appending children.

Why? A table with no tbody or rows is invalid, from that standpoint I
think it's better to add it after having added all it's descendants.

See the link at the bottom about memory leaks in IE.

Do you know of any cases where they *must* be added afterward?

// Set the style for the table
tblGrid.setAttribute("class","tableGRID")

Use tblGrid.className = "tableGrid" and avoid setAttribute as IE's
implementation is buggy and non-standard.

for (var rowCount=0;rowCount < 10; rowCount++)
{
// Create a tr element
var trGrid = tblGrid.insertRow(-1); // the -1
denotes that it must add it to the end

If you are using insertRow, you can dispense with adding a tbody
manually. insertRow works on any HTMLTable or HTMLTableSection
element.

<URL:http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-39872903>

[...]

// Add the actual value to the td element
tdGrid.appendChild(cellValue);

// Add the td element to the tr element
trGrid.appendChild(tdGrid);

Since insertCell has been used, the td has already been added to the
row. This line effectively does nothing.

}

// Add the tr element to the table body element
(Otherwise it won't work in IE)

You are supposed to append rows to the table body. I believe Firefox
saves you a step by creating one automatically.

Since insertRow was used, there is no need to bother with a tbody
element at all, and the row is already added to the table. If you
were going to do it manually, you should append the row to the tbody,
not the table, but as I said above, there's no need for appendChild at
all.







tblBody.appendChild(trGrid)
}

divTarget.appendChild(tblGrid);
}
else
{
alert("The layer that the grid must be built is cannot
be found.");

All your base is now belong to us.

}
}

You just created a lot of memory leaks. Set all of the variables that
contain element references to null.

How? IE's memory leaks require closures and circular references, I
didn't see any.

That is one of several ways to leak memory in IE.

http://msdn2.microsoft.com/en-us/library/Bb250448.aspx


.



Relevant Pages

  • Re: New DOM elements invisible in IE, fine in FireFox
    ... There are two fixes for that: use insertRow, which adds rows directly to the table, or find the TBODY element and add your rows to that. ... var trNew = tblShowLinks.insertRow; ... Check out the DOM HTMLTableElement and related interfaces: ...
    (comp.lang.javascript)
  • Re: A Sorting Puzzle
    ... document fragments and appendChild, besides other tiny adjustments in code ...     So, a little while ago, I tried that same test under FF: ... Don't use insertRow or insertCell, they are slow, use appendChild ... replace the original tbody with the new ...
    (comp.lang.javascript)
  • Re: Dynamically Generated table does not apply styles
    ... Append the table to its container before appending children. ... A table with no tbody or rows is invalid, ... If you are using insertRow, you can dispense with adding a tbody ... contain element references to null. ...
    (comp.lang.javascript)
  • Re: Internet Explorer insertRow/insertCell failure
    ... It seems that Internet Explorer doesn't respond correctly to either ... insertRow() or insertCell, if the object that calls this method isn't ... might be that a tbody must belong to a table, and a row to a tbody and a ... add the row to the rows collection for the table. ...
    (comp.lang.javascript)
  • Re: ie6 Insert Row at specific Row Index of Table
    ... The tbody is created when the HTML source for the table is parsed, whether the tags are there or not because that is what the HTML 4 spec says should happen. ... It is not created as a result of using insertRow. ... Not rubbish, ...
    (comp.lang.javascript)