createElement problem

S

sg_maat

I have a little problem with createElement(and msie).

I was experimenting a bit with createElement and made the following
script:
<script>
var tmp = document.createElement("div");
tmp.setAttribute("name", "tmpdiv2");
tmp.setAttribute("id", "calendar");
var image = document.createElement("img");
image.setAttribute("src", "img/ok.gif");
tmp.appendChild(image);

document.getElementById("body").appendChild(tmp);
</script>

Now this script works fine in msie, netscape, mozilla, firefox and
opera.

Then i made the following script:
//create new element div
var tmp = document.createElement("div");
tmp.setAttribute("name", "tmpdiv");
tmp.setAttribute("id", "calendar");

var table = document.createElement("table");
table.setAttribute("border", "1");
var tr1 = document.createElement("tr");
var td1 = document.createElement("td");
var text = document.createTextNode("Test Text");

td1.appendChild(text);
tr1.appendChild(td1);
table.appendChild(tr1);
tmp.appendChild(table);

document.getElementById("body").appendChild(tmp);
</script>

But this script show notthing in msie(other browser work fine). And my
question really is why???

Stephan Maat
 
K

kaeli

var table = document.createElement("table");
table.setAttribute("border", "1");
var tr1 = document.createElement("tr");
var td1 = document.createElement("td");
var text = document.createTextNode("Test Text");

td1.appendChild(text);
tr1.appendChild(td1);
table.appendChild(tr1);

This worked for me:
(note: document.body, not document.getElementById("body") and the addition of
tbody in the table)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
</head>

<body>
<script>
var tmp = document.createElement("div");
tmp.setAttribute("name", "tmpdiv");
tmp.setAttribute("id", "calendar");

var table = document.createElement("table");
table.setAttribute("border", "1");
var tbody = document.createElement("tbody");
var tr1 = document.createElement("tr");
var td1 = document.createElement("td");
var text = document.createTextNode("Test Text");

td1.appendChild(text);
tr1.appendChild(td1);
tbody.appendChild(tr1);
table.appendChild(tbody);
tmp.appendChild(table);

document.body.appendChild(tmp);
</script>
</body>
</html>


--
--
~kaeli~
Experience is something you don't get until just after you
need it.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
 
S

sg_maat

thanks,

including a tbody did the trick.
And both document.body and document.getElementById("body") work for
appendChild().

Is there a reason why msie needs a tbody and opera, netscape, mozilla
and firefox don't???

Stephan Maat
 
K

kaeli

including a tbody did the trick.
And both document.body and document.getElementById("body") work for
appendChild().

I had problems with document.getElementById("body") for some odd reason.
I often have problems for odd reasons. *grins*
Is there a reason why msie needs a tbody and opera, netscape, mozilla
and firefox don't???

MSIE sucks ass? ;)

--
 

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
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top