Welcome to WebmasterWorld Guest from 54.205.20.160

Forum Moderators: open

Message Too Old, No Replies

Dynamically Updating Body Text with Javascript

How would you add to the body text after a page has loaded?

   
1:29 pm on Jun 13, 2003 (gmt 0)

10+ Year Member



I've got a program written in javascript that takes a while to load and I want to display the output sequentially, rather than making the user wait until the program has completed. Is there a good way, using javascript, to update the body text after the page has loaded?
4:30 pm on Jun 13, 2003 (gmt 0)

10+ Year Member



write() method
4:31 pm on Jun 13, 2003 (gmt 0)

10+ Year Member



document.write("Dog");
10:20 am on Jun 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Take care... If you use document.write() after the page has loaded it will completely rewrite (i.e. obliterate) the page, not append to it...

To "...update the body text after it has loaded...", do as follows:

Say in your html you have <div id="blah">some text</div>

Then in your javascript which gets executed using the onload method:
document.getElementById("blah").innerHTML = "Different Text";

Also, you can add child nodes (e.g. divs or whatever tag you want) with createElement() and appendChild()
e.g. say you have <div id="table_holder"> </div>
Then you can do:
var table_div = document.getElementById("table_holder");
var table_to_insert = document.createElement("table");
table_div.appendChild(table_to_insert);

Similarly, you can add tr's as children of the table_to_insert and td's as their children... or whatever tags you want to add.

Note that all this may not help with your initial problem (getting the page to load faster). All the javascript needs to get downloaded... Describe what you are trying to do in more detail, and someone may be able to offer more help.

Hope that makes sense

Shawn

11:54 am on Jun 14, 2003 (gmt 0)

10+ Year Member



You could look into innerHTML for this.