rollOrDie Posted February 4, 2009 Share Posted February 4, 2009 It doesn't pop up with an error message, it's just that the table just doesn't appear function tableBuild () { var container = document.getElementById ('container'); // build head var headName = document.createTextNode ('Name'); var headAge = document.createTextNode ('Age'); var th1 = document.createElement ('th'); var th2 = document.createElement ('th'); var tr = document.createElement ('tr'); var table = document.createElement ('table'); // append th1.appendChild (headName); tr.appendChild (th1); table.appendChild (tr); container.appendChild (table); alert (table.nodeName); } window.onload = tableBuild; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <script type="text/javascript" src="ajaxStudent.js"></script> </head> <div id="container"> This is the container </div> <body> </body> </html> It works okay in FF (surprisingly). Also, when I alert the nodeName, even IE recgnises it as a table, so I don't know why it isn't displaying it? Quote Link to comment Share on other sites More sharing options...
webster08 Posted February 4, 2009 Share Posted February 4, 2009 try to give your "th" an id; with setAttribute() - example below: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <script type="text/javascript"> function tableBuild() { var txt = document.createElement("p"); txt.setAttribute("id","testing"); document.getElementById("container").appendChild(txt); var tester = document.createTextNode("Hello World!"); document.getElementById("testing").appendChild(tester); } window.onload = function() { tableBuild(); } </script> </head> <div id="container"> This is the container </div> <body> </body> </html> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.