Atli 5,058
Expert 4TB
Hi everybody.
I'm making a Javascript system to build tables, so I can view large tables in smaller pieces. I use the "document.createElement" and "appendChild" methods to create and remove elements from my table.
Got everything working, no problems. Until I test my code in IE.
After a little investigation, I create this: -
<div id="ListContainer" class="Info">
-
<table id="ListTable">
-
<tr>
-
<td>Hello</td>
-
</tr>
-
</table>
-
</div>
-
-
<script type="text/javascript">
-
var table = document.getElementById("ListTable");
-
var newRow = document.createElement("tr");
-
var newCol = document.createElement("td");
-
newCol.innerHTML = "Row2";
-
newRow.appendChild(newCol);
-
table.appendChild(newRow);
-
</script>
-
As before, this works in Firefox, which I use to debug my script. But fails in IE.
Weird thing is that IE usually flashes the error icon in the bottom-left corner when a script is broken, but that doesn't happen now.
Nothing happens, no errors, no changes.
I can't find anything wrong with this code.
Anybody know what is going on there?
13 16150 gits 5,390
Expert Mod 4TB
hi ...
i think i remember that in IE you have to use the tablebody (<tbody>) to append rows ... that will work in FF/Moz too ... so you don't need a different code ... just extend it ... :)
kind regards
Atli 5,058
Expert 4TB
Ahhh, yet another brilliant IE feature!
Just added a <tbody> element between my table and the new rows and everything started working perfectly.
Thanks mate :)
gits 5,390
Expert Mod 4TB
hi Atli ...
in this case i think IE handles the table quite strict ... while the other browsers do not ... have a look here ...
kind regards
Atli 5,058
Expert 4TB
That's interesting.
I wonder tho. If you take a look further down the page, you can see that the examples there don't use the <theader>, <tfooter> and <tbody> elements.
Wonder if they should be optional rather than required as IE handles them.
Lots of other interesting stuff there to.
Thanks mate.
gits 5,390
Expert Mod 4TB
as far as i understood ... browsers should be able to handle it gracefully for backwards-compatibility so IE's strict handling is really strange behaviour ... especially since it handles other things not the strict way ... the good news are: the other browsers can handle it too so we don't need to code twice ;) ... or need some workarounds this time ... while discovering it, it seems to be silly but once you know then you may handle it very straight :) ...
kind regards
Yes, IE's strict handling in this case is indeed strange. I think, though, that it is problematic simply because of the number of hours spent figuring out what the problem might be as well as the sore foreheads, damaged keyboards and grey hairs!
gits 5,390
Expert Mod 4TB
Yes, IE's strict handling in this case is indeed strange. I think, though, that it is problematic simply because of the number of hours spent figuring out what the problem might be as well as the sore foreheads, damaged keyboards and grey hairs!
yes ... i agree ... or simply ask here in the forum to avoid that :)
Hello,
I've been having problems with appendChild on IE. Everything works on other browsers. I found this thread and amended my script to what has been explained above, by adding a <tbody> but it still doesn't work in IE. the code is below. can anyone spot anything I'm doing wrong..?
My Ajax code: -
for(var i=0; i<_post.length; i++)
-
{
-
rank++;
-
var _time = response.getElementsByTagName('time')[i].firstChild.data;
-
var _name = response.getElementsByTagName('name')[i].firstChild.data
-
-
var tb= document.getElementById('posts');
-
var tr = document.createElement('TR');
-
tb.appendChild(tr);
-
var td = document.createElement('TD');
-
tr.appendChild(td);
-
td.innerHTML= rank;
-
var td2 = document.createElement('TD');
-
tr.appendChild(td2);
-
td2.innerHTML= _name;
-
var td3 = document.createElement('TD');
-
tr.appendChild(td3);
-
td3.innerHTML= _time;
-
}
-
and my HTML code: -
<TABLE style='float:left' border='1' id='rankingTable'>
-
<TR><TH COLSPAN='3'>Top 100</TH></TR>
-
<TR><TH>#</TH><TH>Name</TH><TH>Score</TH></TR>
-
-
<tbody id='posts'>
-
</tbody>
-
-
</TABLE>
-
Hope to here from someone soon?
First of all, welcome to Bytes!
Now, onto your question: whenever you use createElement and appendChild, start off by creating the elements in parent to child order and then append them in reverse order, i.e. from child to parent. For example, your code becomes: -
var tb= document.getElementById('posts');
-
var tr = document.createElement('TR');
-
var td = document.createElement('TD');
-
td.innerHTML= rank;
-
var td2 = document.createElement('TD');
-
td2.innerHTML= _name;
-
var td3 = document.createElement('TD');
-
td3.innerHTML= _time;
-
tr.appendChild(td);
-
tr.appendChild(td2);
-
tr.appendChild(td3);
-
tb.appendChild(tr);
-
tables have there own dom functions - row = table.insertRow()
-
cell = row.insertCell()
both functions take params for where the index should be
functions work in both IE and FF
gits 5,390
Expert Mod 4TB
yes that is right ... for a comparison of compat-issues with different dom-operations you may have a look here ...
kind regards
@gits, thanks for your suggestion , it helped me in solving the same problem
Sign in to post your reply or Sign up for a free account.
Similar topics
by: kie |
last post by:
hello,
i have a table that creates and deletes rows dynamically using
createElement, appendChild, removeChild.
when i have added the required amount of rows and input my data, i
would like to...
|
by: kie |
last post by:
hello,
when i create elements and want to assign events to them, i have
realised that if the function assigned to that element has no
parameters, then the parent node values can be attained.
...
|
by: Ivo |
last post by:
I have this code to add a row to a table:
var r=document.createElement('tr');
var c=document.createElement('td');
var cn=c.cloneNode(false);
cn.className='tdname';...
|
by: sg_maat |
last post by:
I have a little problem with createElement(and msie).
I was experimenting a bit with createElement and made the following
script:
<script>
var tmp = document.createElement("div");...
|
by: Arpan |
last post by:
Using DOM, this is how I am appending data to an existing XML file
which is named AppendData.xml (the root element of AppendData.xml is
<ProductList>):
<script runat="server">
Sub...
|
by: Andrew Poulos |
last post by:
When I run the following code in FF 1.5 and 2, and IE 6 on my computer
the table and image appears. When I run it on the client's XP machine it
appears under FF 1.5 but under IE 6 the window is...
|
by: acecraig100 |
last post by:
I am fairly new to Javascript. I have a form that users fill out to
enter an animal to exhibit at a fair. Because we have no way of
knowing, how many animals a user may enter, I created a table...
|
by: Tarik Monem |
last post by:
Why am I having so much trouble with using DOM in IE & Opera to create, then remove an Object & Embedded element?
Here's the code that works in Firefox (Mac/Win/Linux) and Safari, but not on IE or...
|
by: vunet |
last post by:
It is recommended by some sources I found to create IFrames in IE
using
document.createElement('<iframe src="#">')
instead of document.createElement('iframe').
Why and what browser versions to...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |