faqts : Computers : Programming : Languages : JavaScript

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

110 of 116 people (95%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

How to change a normal text statement on html page using javascript without reloading?

Apr 4th, 2008 19:49
ha mo, Iván Rivera, Jap Boon Churn,


The easiest way is accessing the innerHTML property of the element you
want to modify. This works in NS6 and IE5. Suppose you have a named
element in your page like this:
  <h1 id="header">Boring news</h1>
From any script, you can do:
  myH1=document.getElementById('header');
  myH1.innerHTML='Breaking news!!!';
And that's all. Real easy, isn't it?
Note that this way you can insert any HTML you like inside an element
and have it parsed and displayed instantly by the browser.
Since IE4 does not implement getElementById(), you can substitute it
with the document.all collection: document.all['header'].innerHTML
allows you the same level of access to your element.
Hope it helps.
Iván
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com