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?

.adboxdiv {
      float: left;
      margin: 0px 15px 15px 0px

<script language = "Javascript">

function addelement() {
      var pdiv = document.createElement("div");
      var ptable = document.createElement("table");
      var ptbody = document.createElement("tbody");
      var prow = document.createElement("tr");
      var pcell = document.createElement("td");



      document.getElementById("maincell").insertBefore(pdiv, document.getElementById('tablediv'));            


<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></table></div>



<input type = "submit" value = "add a table" onclick = "addelement()">
<input type = "submit" value = "delete table" onclick = "removeelement()">

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try using the className property as an extension to setAttribute("class"):

     pdiv.className = "adboxdiv"


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I am not sure about the technical reasons why msIE behaves this way, but I know msIE has difficulties which some of the basic dom operations like setAttribute.

chsalviaAuthor Commented:
Thanks!  That worked nicely.  
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.