...

View Full Version : document.write(string) so why not div.write(string) ?



Phényx
01-14-2003, 12:02 AM
Hi !

I've created a labelled <div> section, and want to know if there is a javascript command to write something in the <div> section (like the document.write(string) command does to the wole document)

thx ;-)

chrismiceli
01-14-2003, 12:19 AM
give the div an id
<div id="divid"></div>
<script type="text/javascript">
document.getElementById("divid").innerHTML = "hi";
</script>
you could also put html in the div just like you could w/ document.write();

Phényx
01-15-2003, 01:04 PM
Thanks !

Your code is great but try this one :
It works both on IE and Mozilla :thumbsup:

<script>
function WriteDiv(text, id) {

if (document.getElementById) {
x = document.getElementById(id);
x.innerHTML = '';
x.innerHTML = text;
}
else if (document.all) {
x = document.all[id];
x.innerHTML = text;
}
}
</script>

Borgtex
01-15-2003, 01:30 PM
Simplified, assuming that it's IE or Mozilla:

<script>
function WriteDiv(text, id)
{
x = document.all?document.all[id]:document.getElementById(id);
x.innerHTML = text;
}
</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum