ava script tutorial - a new approach by Ken J Ward

Java Script Tutorial -

Inserting Text

Enter some text in the box below and click on the button "Modify Text".

This text changes

Originally, the above paragraph says, "This text changes", but after entering "Hello" in the box and clicking the button, the text becomes the same as the text in the box above (in this case "Hello"). Try entering different text, including none at all and see what happens.

Here is the code for this function:

<script type="text/javascript">


function modifyText()


//we get the paragraph object using "getElementById"

//using the ID of the paragraph

var para = document.getElementById('myPara1');


//we then set the value of the lastChild.nodeValue to the

// text input box value.

para.lastChild.nodeValue =






Many years ago, when I wrote the document.write series in JavaScript1, I was struggling to find a way to change text in a page after it had loaded, and for the code to work in the main browsers. Now we have such code that works reliably in all modern popular browsers.

[If you need to learn more about HTML visit the HTML Tutorial]

I am always pleased to hear from you.
Send your comments to