CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   Automatically hide div after several seconds (http://www.codingforums.com/showthread.php?t=176058)

levani 09-02-2009 07:16 PM

Automatically hide div after several seconds
 
I have a welcome message on my site and would like to automatically hide it after several seconds. I can't find anything usable after searching over the internet. Can anyone help?

Thanks in advance.

Amphiluke 09-02-2009 07:26 PM

Do you need help in searching over the internet?
https://developer.mozilla.org/en/DOM/window.setTimeout

Philip M 09-02-2009 07:46 PM

You don't seem to have tried very hard!

Code:

<html>
<head>

<script type = "text/javascript">

function hideMessage() {
document.getElementById("message").style.display="none";
}

function startTimer() {
var tim = window.setTimeout("hideMessage()", 5000);  // 5000 milliseconds = 5 seconds
}

</script>
</head>

<body onload = "startTimer()">

<div id = "message" style="display:block">Welcome Message</div>

</body>
</html>


BTW, the time to say "thanks" is afterwards, not beforehand which gives the - doubtless unintended - impression that you take other people's voluntary unpaid assistance for granted. Or as British politician Neil Kinnock put it, "Don't belch before you have had the meal." Prefer to use "please" beforehand and if you find a response helpful then you can use the "Thank User For This Post" button.


All times are GMT +1. The time now is 02:36 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.