473,811 Members | 2,717 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to set text in a td through dom

Hello,

What's up with this?

I've got a <td id="container" > and want to set the text in this cell like
....

var container = document.getEle mentById('conta iner');
container.data = "Data in cell";

but can only seem to do it like this ...

var label = document.create TextNode("Data in cell");
container.appen dChild(label);

which seems to actually leave me with two text nodes.
Thanks,

Bill
Jul 20 '05 #1
3 8630
Ok ... It appears that you need *something* to start with between the <td>
and the </td>

So I have ...

<td id=container>&n bsp;</td>

then I can do ..

var container = document.getEle mentById('conta iner');
container.data = "Data in cell";

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.
"Bill M." <wp*********@ho tmail.com> wrote in message
news:6c******** *************** ***@msgid.megan ewsservers.com. ..
Hello,

What's up with this?

I've got a <td id="container" > and want to set the text in this cell like
...

var container = document.getEle mentById('conta iner');
container.data = "Data in cell";

but can only seem to do it like this ...

var label = document.create TextNode("Data in cell");
container.appen dChild(label);

which seems to actually leave me with two text nodes.
Thanks,

Bill

Jul 20 '05 #2
"Bill M." <wp*********@ho tmail.com> writes:

[topposting fixed]
"Bill M." <wp*********@ho tmail.com> wrote in message
news:6c******** *************** ***@msgid.megan ewsservers.com. ..
I've got a <td id="container" > and want to set the text in this cell like
...

var container = document.getEle mentById('conta iner');
container.data = "Data in cell";
If the td has a text node inside it, you can use
container.first Child.nodeValue = "Data in cell";
but can only seem to do it like this ...

var label = document.create TextNode("Data in cell");
container.appen dChild(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.remov eChild(containe r.firstChild);

Ok ... It appears that you need *something* to start with between the <td>
and the </td>

So I have ...

<td id=container>&n bsp;</td>

then I can do ..

var container = document.getEle mentById('conta iner');
container.data = "Data in cell";
Does it work? I didn't think the td element had a "data" property.
However,
container.first Child.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/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3
[snip]
Does it work? I didn't think the td element had a "data" property.
However,
container.first Child.data = "Data in cell";
would work (equivalent to .nodeValue).
Sorry my BAD; I left out the firstChild. However, this still appears not to
work unless there is some text already there.
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.


Ok. I see. I'm getting messed up by peering too deeply into my Mozilla DOM
Inspector. Every Element appears as a Node with a text child node whether or
not the text is there.

Why DOM Inspector is showing text nodes when they're not initialized I'm not
sure. I think they must be there in some state anyway. The odd thing is how
this 'sleeping' textnode appears to go unused when you append a text node.
That is, DOM Inspector will show 2 text nodes (that could be normalized I
guess) after appending a text node to a <td> element.

cheers,

Bill
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2097
by: Kenneth P | last post by:
Hi, I have a very good book on asp.net Sams ASP.NET Tips, Tutorials and Code ISBN 0-672-32143-2 and is trying to teach myself from examples from this book Chapter 16. Anyway I come quite close when trying to run one example but then I get this message I don't understand: "This .resources file shouldn't be used with this reader. Your resource
25
4079
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
3
1334
by: The One | last post by:
Have created a form to pop up with 2 option I then wish to write the text that is in the option button chose back to the original form using the code below but it gives me an exception error so could any please help me. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim frm As Form1 Dim text As String
14
2214
by: deercreek | last post by:
Could use some help. I don't know if I can even do whatI'm trying to do. I have a text box in a report under the details section. It will return a value for each line on a sepcific record set. There may be 1 line or 10 lines. What I want to do is sum the totals in that text box. I tried putting the following code in the control source. It dosn't like it. I don't know if I'm just putiing it in incorrectly or if it will work at all. Thanks...
4
2299
by: 28tommy | last post by:
Hi, I'm trying to find scripts in html source of a page retrieved from the web. I'm trying to use the following rule: match = re.compile('<script + src=+>') I'm testing it on a page that includes the following source: <script language="JavaScript1.2"
5
3651
by: snicks | last post by:
I'm trying to exec a program external to my ASP.NET app using the following code. The external app is a VB.NET application. Dim sPPTOut As String sPPTOut = MDEPDirStr + sID + ".ppt" Dim p As New System.Diagnostics.Process 'p.Start(MDEPDirStr & "macrun.exe", sPPTOut) p.Start("C:\WINDOWS\SYSTEM32\CALC.EXE") 'p.Start("C:\WINDOWS\SYSTEM32\macrun.exe", sPPTOut)
11
1900
by: =?Utf-8?B?TWlrZSBDb2xsaW5z?= | last post by:
I am trying to get the text of an item in a GridView, but am doing something wrong. Can someone help me with the correct C# statement I need? Below is my GridView and my attempt to get the control. Thank you. string option = ((TextBox)dgDropDownMenus.Items.FindControl("txtName")).Text; -----------------------DataGrid------------------------------------------- <asp:datagrid id="dgMenus" style="Z-INDEX: 101; LEFT: 0px; POSITION:
1
3153
by: rsteph | last post by:
I've got some product information pages, with images and text, all setup within a table. I'm trying to add a small image in the upper right hand corner of the content div (where all the important information is). I've got the product name at the top, left aligned and typically as a two lined header, and I'd like to add a small logo to the right of that, either right beside it, or in the far right corner. could anyone help me with how to set...
5
2113
by: BlueDream | last post by:
What I'm trying to do is simply scan in a file then whenever I get a space, turn it into 2 spaces. Whenever I get a carriage return, turn it into 2 spaces.. An example of what I'm trying to achieve with this body of text. An example of what I'm trying to achieve with this body
6
3219
by: Doogie | last post by:
Hi I have an img control I am trying to hide upon certain types of commands in my code behind. When to hide it is directly tied to a asp:dropdownlist control. So depending on what the user selects in that dropdownlist, this image will be hidden or be displayed. I have tied the onselectedindexchanged value of the dropdownlist to a c-sharp method (not javascript) because other things are being done as well that I want to do server side. ...
0
9728
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10648
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10402
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10135
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9205
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6890
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5554
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4339
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3018
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.