Welcome to WebmasterWorld Guest from

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)

Junior Member

10+ Year Member

joined:Nov 29, 2002
votes: 0

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 June 13, 2003 (gmt 0)

New User

10+ Year Member

joined:Apr 5, 2003
votes: 0

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

New User

10+ Year Member

joined:Apr 5, 2003
votes: 0

10:20 am on June 14, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 27, 2003
votes: 0

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");

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


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

Junior Member

10+ Year Member

joined:June 13, 2003
votes: 0

You could look into innerHTML for this.

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members