469,645 Members | 1,641 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,645 developers. It's quick & easy.

IE createElement issue

Hi everyone, I am having an issue with using document.createElement in IE (at least I think that's what the problem is). The following code snippet works in FireFox no problem, but doesn't show anything in IE. No errors are thrown during the execution. Does anyone know of any IE gotchas that would be pertinent to this case? Thanks!

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type='text/javascript'>
  4.     window.onload = function(){
  5.         var tableRow = document.createElement('tr');
  6.         var tableCell = document.createElement('td');
  7.         var textNode = document.createTextNode('text goes here');
  8.         var table = document.getElementById('myTable');
  9.  
  10.         tableCell.appendChild(textNode);
  11.         tableRow.appendChild(tableCell);
  12.         table.appendChild(tableRow);
  13.     };
  14. </script>
  15. </head>
  16. <body>
  17. <table id='myTable' />
  18. </body>
  19. </html>
  20.  
Jan 19 '07 #1
2 1577
acoder
16,027 Expert Mod 8TB
You're missing the table body (tbody) element:
Expand|Select|Wrap|Line Numbers
  1. window.onload = function(){
  2.  var tableBody = document.createElement('tbody');
  3.  var tableRow = document.createElement('tr');
  4.  var tableCell = document.createElement('td');
  5.  var textNode = document.createTextNode('text goes here');
  6.  var table = document.getElementById('myTable');
  7.  
  8.  tableCell.appendChild(textNode);
  9.  tableRow.appendChild(tableCell);
  10.  tableBody.appendChild(tableRow);
  11.  table.appendChild(tableBody);
  12.  
See this page for more detail.
Jan 20 '07 #2
Adding TBODY resolved the issue. Thank you!
Jan 24 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by sg_maat | last post: by
3 posts views Thread by Arpan | last post: by
9 posts views Thread by Andrew Poulos | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.