Credit Cards - Debt Consolidation - Magnetic Bead Bracelet - Expekt bonuses - Cheap Plane Tickets

PDA

View Full Version : simple js doesn't work with IE7 (work with FF1.5)


gpazi
Jun 10th 2007, 3:42 am
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>

krakjoe
Jun 10th 2007, 3:53 am
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>

gpazi
Jun 10th 2007, 4:03 am
IE requires a tbody element to insert a table using the DOM