simple js doesn't work with IE7 (work with FF1.5)

Discussion in 'JavaScript' started by gpazi, Jun 10, 2007.

  1. #1
    Hi,
    With IE7, the following code doesn't add the table to the page when button is clicked.
    the code is also uploaded to http://startupisrael.com/gpazi/triptouch/test.php

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    </head>
    <body>
    <script language="Javascript" type="text/javascript">
    function func()
    {
    var mydiv = document.getElementById("mydiv");

    var mytable = document.createElement("table");
    var mytr = document.createElement("tr");
    var mytd = document.createElement("td");
    var mytext = document.createTextNode("this is my text");
    mytd.appendChild(mytext);
    mytr.appendChild(mytd);
    mytable.appendChild(mytr);
    mydiv.appendChild(mytable);
    }
    </script>

    <div id="mydiv"><button onclick="func();">click</button></div>
    </body>
    </html>
     
    gpazi, Jun 10, 2007 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    It's trying it's hardest to be xhtml compliant, use a different element like div

    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
    <html>  
    <head>
    </head>
    <body>
    <script	language="Javascript" type="text/javascript">
    	function func()
    	{
    		var wm_previewDiv = document.getElementById("aaa");
    
    		var div = document.createElement( "div" );
    		var textNode = document.createTextNode( "date" );
    		div.appendChild( textNode );
    		wm_previewDiv.appendChild( div );
    	}
    </script>
    
    <div id="aaa"><button onclick="func();">click</button></div>
    </body>
    </html>
    
    HTML:
     
    krakjoe, Jun 10, 2007 IP
  3. gpazi

    gpazi Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    IE requires a tbody element to insert a table using the DOM
     
    gpazi, Jun 10, 2007 IP