View Full Version : How to dyamically change content on page?

12-10-2006, 07:11 PM
How can I , for example, replace an image with another image, or some text, Or change the information in some text. But All this has to happen dynamically and without refreshing the page. How can this be achieved best?

12-10-2006, 11:53 PM
I would use the Document Object Model (http://en.wikipedia.org/wiki/Document_Object_Model). Example:


function changeText()
var newText = document.createTextNode('This is the new text.');
var container = document.getElementById('textDiv');
container.replaceChild(newText, container.firstChild);


<div id="textDiv" onclick="changeText()">
This is the old text.

Note that the change need not be user-prompted. You can call changeText() upon window.onload or whe(r|n)ever you want...

12-11-2006, 03:34 AM
thanks man: exactly what I was looking for, but how could I make a timer instead of the onclick function?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum