How to change page contents dynamically using JavaScript

Web programming topics
Post Reply
User avatar
Shane
Captain
Captain
Posts: 226
Joined: Sun Jul 19, 2009 9:59 pm
Location: Jönköping, Sweden

How to change page contents dynamically using JavaScript

Post by Shane » Sun Feb 28, 2010 10:47 pm

Say we have following simple text:

Code: Select all

<div ID="testing">ROBOT.LK</div>
 
In Internet Explorer 4 or above, the script to change the above text is:

Code: Select all

document.all.testing.innerHTML = "A very nice site!" 
In Netscape 6 (works in IE6 as well), the idea to alter a text is very similar, except in the precise syntax:

Code: Select all

document.getElementById("testing").innerHTML = "A very nice site!" 
In Netscape 4:
First we need to set the required tags as follows.

Code: Select all

<ilayer name="testing"><layer name="testing2">ROBOT.LK</layer></ilayer> 
Then the code is as below:

Code: Select all

document.testing.document.test2.document.write("A very nice site!")
document.testing.document.test2.document.close()
 
Post Reply

Return to “Web programming”