"Bill M." <wp*********@hotmail.com> writes:
[topposting fixed]
"Bill M." <wp*********@hotmail.com> wrote in message
news:6c**************************@msgid.meganewsse rvers.com...
I've got a <td id="container"> and want to set the text in this cell like
...
var container = document.getElementById('container');
container.data = "Data in cell";
If the td has a text node inside it, you can use
container.firstChild.nodeValue = "Data in cell";
but can only seem to do it like this ...
var label = document.createTextNode("Data in cell");
container.appendChild(label);
That works too.
which seems to actually leave me with two text nodes.
It does. You can remove the existing text node first:
container.removeChild(container.firstChild);
Ok ... It appears that you need *something* to start with between the <td>
and the </td>
So I have ...
<td id=container> </td>
then I can do ..
var container = document.getElementById('container');
container.data = "Data in cell";
Does it work? I didn't think the td element had a "data" property.
However,
container.firstChild.data = "Data in cell";
would work (equivalent to .nodeValue).
But this is strange because there should exist a text node (CharacterData)
for every element, even if there is no text; at least as I understand the
model.
I don't think so. Every CharacterData has a "data" property, but the td
*Element* is not a CharacterData.
The inheritance hierarchy is:
+------+
|/Node/|
+------+
/ \
+-------+ +---------------+
|Element| |/CharacterData/|
+-------+ +---------------+
\
+----+
|Text|
+----+
The td element is an Element. Its first child node is a Text.
You try to set the "data" property of something that is not a
CharacterData. That just creates a new property, but otherwise
does nothing.
/L
--
Lasse Reichstein Nielsen -
lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'