473,472 Members | 1,800 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

insert element at the end of a node

hey,

i'm a little frustrated. i'm trying to add a td element with
appendChild as last child to a tr element. but it adds the td element
always as first child to the tr element?
although appendChild should add the new child at the end. what could be
wrong?

Oct 7 '06 #1
6 2565


strauchdieb wrote:

i'm trying to add a td element with
appendChild as last child to a tr element. but it adds the td element
always as first child to the tr element?
although appendChild should add the new child at the end. what could be
wrong?
Show us the relevant code (script and HTML), then tell us which
browser(s) you are testing with, then we can probably help.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 7 '06 #2
oh sorry, i've totally forgotten to post the code. sorry...

here's the code:

for (var i = 0; i < tableBody.rows.length; i++)
{
var cell = document.createElement("td");
tableBody.rows[i].appendChild(cell);
}

that's nothing fancy, i think.
i tested it with IE and firefox

Oct 7 '06 #3
strauchdieb wrote on 07 okt 2006 in comp.lang.javascript:
oh sorry, i've totally forgotten to post the code. sorry...

here's the code:

for (var i = 0; i < tableBody.rows.length; i++)
{
var cell = document.createElement("td");
tableBody.rows[i].appendChild(cell);
}

that's nothing fancy, i think.
i tested it with IE and firefox
Since you did not quote, we have to search back to your Q.

Please always quote on usenet.

it was:
i'm a little frustrated. i'm trying to add a td element with
appendChild as last child to a tr element. but it adds the td element
always as first child to the tr element?
although appendChild should add the new child at the end. what could be
wrong?
Nothing is wrong, try the following:

<table id='tableBody' border='1'>
<tr><td>mmmmm
<tr><td>mmmmm
<tr><td>mmmmm
<tr><td>mmmmm
</table>

<script type='text/javascript'>
var tableBody = document.getElementById('tableBody')
for (var i = 0; i < tableBody.rows.length; i++){
var cell = document.createElement("td");
tableBody.rows[i].appendChild(cell);
cell.innerHTML = 'Hello!'
}
</script>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 7 '06 #4


strauchdieb wrote:

for (var i = 0; i < tableBody.rows.length; i++)
{
var cell = document.createElement("td");
tableBody.rows[i].appendChild(cell);
}
i tested it with IE and firefox
I don't see anything wrong with the code snippet, but I don't see
anything wrong with the results I get with
<http://home.arcor.de/martin.honnen/javascript/2006/10/test2006100801.html>
which uses the code snippet (with one variation to allow to put some
content in the newly created cells). The only problem is that IE 6 does
not render borders around empty cells thus if the above is all you
really do then you will not see much at the end of the row looking like
an empty cell, but still you see the change at the end of the row and
not at the beginning as you original post claimed.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 8 '06 #5
it inserts the new td's definitely as first child.

my table html looks like this, before inserting with appendChild:
<TABLE>
<TBODY>
<TR>
<TH>1</TH>
<TD id=1x1></TD>
<TD id=1x2></TD>
<TD id=1x3></TD>
</TR>
</TBODY>
</TABLE>

after inserting it looks like this:
<TABLE>
<TBODY>
<TR>
<TH>1</TH>
<TD>inserted</TD>
<TD>inserted</TD>
<TD>inserted</TD>
<TD id=1x1></TD>
<TD id=1x2></TD>
<TD id=1x3></TD>
</TR>
</TBODY>
</TABLE>

what i want is:
<TABLE>
<TBODY>
<TR>
<TH>1</TH>
<TD id=1x1></TD>
<TD id=1x2></TD>
<TD id=1x3></TD>
<TD>inserted</TD>
<TD>inserted</TD>
<TD>inserted</TD>
</TR>
</TBODY>
</TABLE>

has anybody an idea, how i can make this happen? is there a workaround
for this problem?

thanks for your help

Evertjan. wrote:
strauchdieb wrote on 07 okt 2006 in comp.lang.javascript:
oh sorry, i've totally forgotten to post the code. sorry...

here's the code:

for (var i = 0; i < tableBody.rows.length; i++)
{
var cell = document.createElement("td");
tableBody.rows[i].appendChild(cell);
}

that's nothing fancy, i think.
i tested it with IE and firefox

Since you did not quote, we have to search back to your Q.

Please always quote on usenet.

it was:
i'm a little frustrated. i'm trying to add a td element with
appendChild as last child to a tr element. but it adds the td element
always as first child to the tr element?
although appendChild should add the new child at the end. what could be
wrong?

Nothing is wrong, try the following:

<table id='tableBody' border='1'>
<tr><td>mmmmm
<tr><td>mmmmm
<tr><td>mmmmm
<tr><td>mmmmm
</table>

<script type='text/javascript'>
var tableBody = document.getElementById('tableBody')
for (var i = 0; i < tableBody.rows.length; i++){
var cell = document.createElement("td");
tableBody.rows[i].appendChild(cell);
cell.innerHTML = 'Hello!'
}
</script>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 8 '06 #6
strauchdieb wrote on 08 okt 2006 in comp.lang.javascript:
it inserts the new td's definitely as first child.
[Please do not toppost on usenet]

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 8 '06 #7

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

Similar topics

5
by: Tony B | last post by:
Hi I need to insert a new node into an exisiting XML file using VBScript. The file has the following structure: <TRANSACTION> <ORDER> <BILLING>... </BILLING> <ORDER_TOTALS>... </ORDER_TOTALS>...
1
by: Rafaela K. Azinhal | last post by:
Please, help me with following code snippet ' Load xml document Dim xmlDoc As New XmlDocument() xmlDoc.Load(http://localhost/VT/reports/VT_actual_owsPivotTable.xml) ' define namespacemanager...
2
by: Beniamin Tecar | last post by:
Hi, I have an xml : <DataRecords> <Point Alias='A' Value='1' Status='0' /> <Point Alias='B' Value='2' Status='0' /> </DataRecords> I have needed by an XSL to insert a node between...
4
by: mike | last post by:
Hello. Let's say I have the following XML document: <ROOT><Element1>Some Text</Element1></ROOT> I want to add a new element after Element1. I tried the following but, naturally, it doesn't...
4
by: neilcancer | last post by:
i wrote a function to insert an elem into a list, but it was wrong,wrong,wrong! and i have no idea about why it was wrong. If anyone know, leave your advice, thank you. #include<stdio.h>...
2
by: Patrick | last post by:
Hi, im trying to first insert a node in the xml file and save it. XmlDocument mDoc = new XmlDocument(); mDoc.Load("struct.xml"); XmlNode singleNode; XmlNode newNode =...
3
by: dmc | last post by:
Can anyone suggest an elegant solution for this problem? I have a source document as follows: <Object Type="Type1"> <Attribute_A>ValueA</Attribute_A> <Attribute_B>ValueB</Attribute_B>...
2
by: Alexander Paul | last post by:
Hi! I'm a newbie to JavaScript and Greasemonkey and just started learning with 'Dive Into Greasemonkey'. I looked for an example on the web, but unfortunately I'm still missing something... I...
10
by: Aditya | last post by:
Hi All, I would like to know how it is possible to insert a node in a linked list without using a temp_pointer. If the element is the first element then there is no problem but if it is in...
0
by: monkeyboysdad | last post by:
I have an xml document - <?xml version="1.0"?> <mstns> <curves id="curve0"> </curves> <classification name="ROUND STN STL BAR"> <material name="DIA 3MM STN STL 316 h9"> ...
0
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,...
0
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,...
0
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...
0
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.