IE createElement issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rpfromuk
    New Member
    • Jan 2007
    • 2

    #1

    IE createElement issue

    Hi everyone, I am having an issue with using document.create Element 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!

    Code:
    <html>
    <head>
    <script type='text/javascript'>
    	window.onload = function(){
    		var tableRow = document.createElement('tr');
    		var tableCell = document.createElement('td');
    		var textNode = document.createTextNode('text goes here');
    		var table = document.getElementById('myTable');
    
    		tableCell.appendChild(textNode);
    		tableRow.appendChild(tableCell);
    		table.appendChild(tableRow);
    	};
    </script>
    </head>
    <body>
    <table id='myTable' />
    </body>
    </html>
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    You're missing the table body (tbody) element:
    Code:
    window.onload = function(){
     var tableBody = document.createElement('tbody');
     var tableRow = document.createElement('tr');
     var tableCell = document.createElement('td');
     var textNode = document.createTextNode('text goes here');
     var table = document.getElementById('myTable');
    
     tableCell.appendChild(textNode);
     tableRow.appendChild(tableCell);
     tableBody.appendChild(tableRow);
     table.appendChild(tableBody);
    See this page for more detail.

    Comment

    • rpfromuk
      New Member
      • Jan 2007
      • 2

      #3
      Adding TBODY resolved the issue. Thank you!

      Comment

      Working...