faqts : Computers : Programming : Languages : JavaScript : Document

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

296 of 470 people (63%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

How can I use javascript to change text in a document that is already loaded?

May 17th, 2001 05:53
Colin Fraser, Eric Sanders,


Try this

<SCRIPT LANGUAGE="JavaScript">
function rewrite() {
  document.all("ONE").innerText = 'This is new text in SPAN ONE';
  document.all("TWO").innerText = 'This is new text in SPAN TWO';
 }

function rewrite2() {
  document.all("ONE").innerText = 'This is the original text in SPAN 
ONE';
  document.all("TWO").innerText = 'This is the original text in SPAN 
TWO';
 }
 </SCRIPT>
<p>
 <SPAN ID="ONE">This is the current text in SPAN ONE</SPAN>
<br>
 <SPAN ID="TWO">This is the current  text in SPAN TWO</SPAN>
<p>
<FORM>
<INPUT TYPE="BUTTON" VALUE="Change Text" onClick="rewrite()">
&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE="BUTTON" VALUE="Change Back" onClick="rewrite2()">
</FORM>


This works in IE5.5 but not NN4.7.