Make a <div> disappear after x number of seconds
Posted: Thu Sep 04, 2003 3:00 pm
How can i set a <div> to diplay: none afet x number of seconds after a page has loaded using javascript.
CHeerz
Mark
CHeerz
Mark
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<script type="text/javascript">
<!--
function doit()
{
document.getElementById('a').style.visibility='hidden';
}
setTimeout('doit()',3000);
//-->
</script>
</head>
<body>
<div style="visibility:visible" id="a">
this is the div
</div>
</body>
[\code]
VinnyCode: Select all
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language=JavaScript>
function getPageItem(itemID) {
if (document.getElementById) {
return document.getElementById(itemID);
}
if (document.all) {
return document.allїitemID];
}
return null;
}
<!--
function slUpdateSpan(newHtml) {
var span_obj = getPageItem("idUpdateableSpan");
if (span_obj) {
if (span_obj.style.display != "inline") {
span_obj.style.display = "inline";
}
span_obj.innerHTML = newHtml;
}
}
function killUpdateSpan() {
var span_obj = getPageItem("idUpdateableSpan");
if (span_obj) {
span_obj.style.display = "none";
}
}
//-->
</script>
</head>
<body>
<div id="idUpdateableSpan"
style="position: absolute;
top: 40%; left: 35%;
width: 30%;
height: 80px;
filter:alpha(opacity=80);
-moz-opacity:80%;
margin:0;
padding:15px;
background-color:#eee;
border:1px solid #333;
text-align: center;
z-index:1000;
display:none;
cursor:default;
"></div>
<script language=JavaScript>
<!--
slUpdateSpan("Yawning...<br><br>");
//-->
</script>
<script language=Javascript>
<!--
setTimeout('killUpdateSpan()',3000);
//-->
</script>
</body>
</html>Code: Select all
function removeElement(id) {
var element = document.getElementById(id);
element.parentNode.removeChild(element);
}