chsalvia
asked on
Creating tables in Internet Explorer
I wrote the following code as a learning experiment to create a simple table using createElement and insertBefore. The code simply creates a button which then lets you add more tables to the page. The table appears as a simple blue box.
But I want each new table to appear next to the previous table, so if you keep clicking the create table button, new tables appear left to right. This is how the code behaves in Firefox. But in Internet Explorer, the tables appear vertically, as if it does not understand the "float" property.
Why does this happen in Internet Explorer, and what are some fixes?
<html>
<head>
<style>
.adboxdiv {
float: left;
margin: 0px 15px 15px 0px
}
</style>
<script language = "Javascript">
function addelement() {
var pdiv = document.createElement("di v");
var ptable = document.createElement("ta ble");
var ptbody = document.createElement("tb ody");
var prow = document.createElement("tr ");
var pcell = document.createElement("td ");
pdiv.setAttribute("class", "adboxdiv" );
ptable.setAttribute("borde r","0");
pcell.setAttribute("width" ,"100");
pcell.setAttribute("height ","50");
pcell.setAttribute("bgColo r","#0000F F");
prow.appendChild(pcell);
ptbody.appendChild(prow);
ptable.appendChild(ptbody) ;
pdiv.appendChild(ptable);
document.getElementById("m aincell"). insertBefo re(pdiv, document.getElementById('t ablediv')) ;
}
</script>
</head>
<body>
<table id = "maintable" border = "0" cellspacing = "0" cellpadding = "0" width = "100%">
<tr><td id = "maincell">
<div id = "tablediv" class = "adboxdiv"><table border = "0"><tr><td width = "100" height = "50" bgColor = =#FF0000"></td></tr></tabl e></div>
</td></tr>
</table>
<input type = "submit" value = "add a table" onclick = "addelement()">
<input type = "submit" value = "delete table" onclick = "removeelement()">
</body>
</html>
But I want each new table to appear next to the previous table, so if you keep clicking the create table button, new tables appear left to right. This is how the code behaves in Firefox. But in Internet Explorer, the tables appear vertically, as if it does not understand the "float" property.
Why does this happen in Internet Explorer, and what are some fixes?
<html>
<head>
<style>
.adboxdiv {
float: left;
margin: 0px 15px 15px 0px
}
</style>
<script language = "Javascript">
function addelement() {
var pdiv = document.createElement("di
var ptable = document.createElement("ta
var ptbody = document.createElement("tb
var prow = document.createElement("tr
var pcell = document.createElement("td
pdiv.setAttribute("class",
ptable.setAttribute("borde
pcell.setAttribute("width"
pcell.setAttribute("height
pcell.setAttribute("bgColo
prow.appendChild(pcell);
ptbody.appendChild(prow);
ptable.appendChild(ptbody)
pdiv.appendChild(ptable);
document.getElementById("m
}
</script>
</head>
<body>
<table id = "maintable" border = "0" cellspacing = "0" cellpadding = "0" width = "100%">
<tr><td id = "maincell">
<div id = "tablediv" class = "adboxdiv"><table border = "0"><tr><td width = "100" height = "50" bgColor = =#FF0000"></td></tr></tabl
</td></tr>
</table>
<input type = "submit" value = "add a table" onclick = "addelement()">
<input type = "submit" value = "delete table" onclick = "removeelement()">
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks! That worked nicely.
-r-