IE DOM appendChild problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • theS70RM
    New Member
    • Jul 2007
    • 107

    IE DOM appendChild problem

    Hey,

    Please try this code:


    Code:
    <html>
    <head>
    <script language="javascript">
    
    function initialise(){	
    		mytable = document.createElement("table");
    		mytr = document.createElement("tr");
    		mytd = document.createElement("td");
    		
    		mytd.innerHTML = "Test";
    		
    		mytr.appendChild(mytd);
    		mytable.appendChild(mytr);
    		
    		mydiv = document.getElementById("test");
    		mydiv.appendChild(mytable);
    		
    		
    		
    		alert(mydiv.innerHTML);
    }
    
    </script>
    <head>
    <body onload="initialise();">
    
    
    <div id="test"></div>
    
    </body>
    </html>

    Seems to work in Firefox but not in IE. I put the alert() in to show that the html is actually inserted into the div but it just doesnt show up


    Can anyone help out with why?


    Cheers

    Andy
  • iam_clint
    Recognized Expert Top Contributor
    • Jul 2006
    • 1207

    #2
    your missing thead... example
    [CODE=javascript]
    <html>
    <head>
    <script language="javas cript">

    function initialise(){
    mytable = document.create Element("table" );
    mythead = document.create Element("thead" );
    mytr = document.create Element("tr");
    mytd = document.create Element("td");

    mytd.innerHTML = "Test";

    mytr.appendChil d(mytd);
    mythead.appendC hild(mytr);
    mytable.appendC hild(mythead);

    mydiv = document.getEle mentById("test" );
    mydiv.appendChi ld(mytable);



    alert(mydiv.inn erHTML);
    }

    </script>
    <head>
    <body onload="initial ise();">


    <div id="test"></div>

    </body>
    </html>
    [/CODE]

    Comment

    • theS70RM
      New Member
      • Jul 2007
      • 107

      #3
      ah yep, thats sorted it

      cheers

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        ...or a tbody. IE for some reason requires a tbody whereas other browsers don't.

        Comment

        Working...