I've noticed that when I add the HTML "<table>" to the innerHTML of a div, IE adds <tbody></tbody></table> automatically, for an example try (note - in the pop up has "<tbody></tbody></table>" that wasn't added): <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head><title>Untitled</title></head> <body> <div id="wwww"></div> <script language="JavaScript" type="text/javascript"> document.getElementById("wwww").innerHTML = "<table>" document.getElementById("wwww").innerHTML = document.getElementById("wwww").innerHTML + "<tr><td>blah</td></tr>" document.getElementById("wwww").innerHTML = document.getElementById("wwww").innerHTML + "</table>" alert(document.getElementById("wwww").innerHTML) </script> </body> </html>
I haven't tried your code yet, but just looking at it I can see that you can simplify greatly to this: document.getElementById("wwww").innerHTML = "<table>" + "<tr><td>blah</td></tr>" + "</table>";
Hey frankcow, That's cool, usually I need to do something like: document.getElementById("wwww").innerHTML = "<table>" --start loop document.getElementById("wwww").innerHTML = "<tr><td>blah</td></tr>" --end loop document.getElementById("wwww").innerHTML = "</table>" the problem is that when I break it up into three pieces IE ends the table before I can start adding the rows.
I've had that with IE, it seems happier when you create tables through createElement() and friends instead of using innerHTML.
Hey Jowan, Would you mind posting a snippet of code show the insertions of a simple table and one row with a data cell using the createElement() method? I'd love to see a quick example of that. Marty
frankcow, Yeah, I really should get in the habbit of doing it that way. Thanks for the reminder. Marty
Unfortunately, I ended up not using that code so I no longer have it. But it comes around to this: http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/table.asp is a reference to IE's table object. It has a rows collection: http://msdn.microsoft.com/workshop/author/dhtml/reference/collections/rows.asp You can either manipulate the rows collection, or use methods like insertRow: http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/insertrow.asp I don't remember which one has worked for me, but I did have lots of problems with building tables in IE using innerHTML. It just wouldn't work. I'd suggest starting with insertRow and similar methods, they are specifically for tables and have a better chance of working. This is all strictly IE specific, of course.
Thanks for the info Jowan... Just in case you're curious I've had a lot of luck with the innerHTML, but only if I write all of the HTML to a variable and then assign that variable to the innerHTML. For example: var myInnerHTML = "<table>" --start loop myInnerHTML += "<tr><td>blah</td></tr>" --end loop myInnerHTML += "</table>" document.getElementById("wwww").innerHTML = myInnerHTML Code (markup): Thanks again...
Not true. insertRow is defined in the W3C DOM and is supported in other browsers. For example, here is the mozilla.org reference page for insertRow. The microsoft pages you listed have examples that are IE specific, but only because they use document.all.
You're right, good catch. I must've used different methods or it just stuck with me that I only had to do this for IE.