Forum Moderators: open

Message Too Old, No Replies

Change div content after 10 seconds

howto change div content after 10 seconds

         

anversli

12:37 pm on Jun 29, 2008 (gmt 0)

10+ Year Member



I need some help with javascript. What I need is a script that changes the content of a div after 10 seconds!

For example:

If the page loads:

Text one will be visible for 10 seconds and than the content will load.

Sorry for my English.

Fotiman

6:49 pm on Jun 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<div id="myDiv">
This will be replaced.
</div>
<script type="text/javascript">
window.onload = function () {
setTimeout(function () {
var div = document.getElementById('myDiv');
div.innerHTML = 'swapped!';
}, 10000);
}
</script>
</body>
</html>

Fotiman

6:51 pm on Jun 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



More info on setTimeout:
[w3schools.com...]

anversli

9:26 pm on Jun 29, 2008 (gmt 0)

10+ Year Member



Thanks Fotiman, its working great.

anversli

10:43 pm on Jun 29, 2008 (gmt 0)

10+ Year Member



Hey Fotiman, is it possible to add a funtion that will start loading div.innerHTML = 'swapped!'; in background while showing myDiv for 10 seconds?