Re: Dynamically Generated table does not apply styles
- From: David Mark <dmark.cinsoft@xxxxxxxxx>
- Date: Wed, 08 Aug 2007 02:02:11 -0700
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
.
- Follow-Ups:
- References:
- Dynamically Generated table does not apply styles
- From: Nikron
- Re: Dynamically Generated table does not apply styles
- From: David Mark
- Re: Dynamically Generated table does not apply styles
- From: RobG
- Dynamically Generated table does not apply styles
- Prev by Date: Re: Dynamically Generated table does not apply styles
- Next by Date: Re: document.referrer as an alternative to history.back()?
- Previous by thread: Re: Dynamically Generated table does not apply styles
- Next by thread: Re: Dynamically Generated table does not apply styles
- Index(es):
Relevant Pages
|