Works in Firefox, not in IE (basic DOM scripting)

J

jdeighan

The following results in a second row, with a cell containing 'xxx',
being added to the table on the web page, but only in Firefox, not in
IE 6. In IE 6, the JavaScript function runs - in fact, the 2 alerts pop
up and the border of the table is set to 1. But, the second row is not
added to the table. Any ideas?


<html>
<head>
<title>Results of JavaScript Test</title>
<script type="text/javascript">
function testJavaScript() {
try {
var table = document.getElementById('mytable');
alert("adding border");
table.setAttribute('border','1');
var txt = document.createTextNode('xxx');
var th = document.createElement('th');
th.appendChild(txt);
var tr = document.createElement('tr');
tr.appendChild(th);
table.appendChild(tr);
alert('done');

}
catch (err) {
alert("ERROR: " + err);
}
}
</script>
</head>
<body id="htmlbody" onload="testJavaScript();">
<table id="mytable" border="0" frame="box">
<tr><th>aaa</th></tr>
</table>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top