Click to See Complete Forum and Search --> : How to change document text with Javascript?


karayan
02-08-2003, 12:31 AM
I must say this one has me baffled, although you would think it obvious. I need to write a script to change part of the text in a document. Is there a way to do this? (For example, you click on a button and the text on the page changes.) The only way I was able to do it is by plaing the text in a named textbox and then changing its .value property. But the textbox is a poor choice. I need to have regular text changed. I have thought of convoluted ways to reload the document, but there must be a simple way. Any clues?

Thanks.

George:confused:

vickers_bits
02-08-2003, 02:47 AM
use the innerText (text only) or innerHTML (html tags and text) properties. eg:

function changeText(){ //ie4+ nn6+
d=document;
if (d.getElementById || d.all){
if (d.getElementById) obj=d.getElementById("myDiv");
else if (d.all) obj=d.all["myDiv"];
obj.innerHTML="<p>whatever</p>";
obj.style.backgroundColor="#0F0F0F";
}
};