Make a <div> disappear after x number of seconds
Moderator: General Moderators
Make a <div> disappear after x number of seconds
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
- Vincent Puglia
- Forum Commoner
- Posts: 67
- Joined: Thu Sep 04, 2003 4:20 pm
- Location: where the World once stood
Hi,
This should provide you with enough to go on:
This should provide you with enough to go on:
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]
VinnyIf you wanna see a cool working example i did, check this out
Mark
Code: 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>- Vincent Puglia
- Forum Commoner
- Posts: 67
- Joined: Thu Sep 04, 2003 4:20 pm
- Location: where the World once stood
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Make a <div> disappear after x number of seconds
This is great - but I makes the DIV disappear, it doesn't remove it, thus closing the space.
Be nice if it disappeared and because in theory, that div has now "gone", so the CSS'd space that was taken up, is no longer there.
Be nice if it disappeared and because in theory, that div has now "gone", so the CSS'd space that was taken up, is no longer there.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Make a <div> disappear after x number of seconds
Think I have it wrong here - it shows the DIV in the code, but it's just not "visible".
Do you know how to literally make it not appear at all - so the entire box "goes" in code ?? I want it to disappear and what's below, moves up.
Do you know how to literally make it not appear at all - so the entire box "goes" in code ?? I want it to disappear and what's below, moves up.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Make a <div> disappear after x number of seconds
You could do something like this:
Code: Select all
function removeElement(id) {
var element = document.getElementById(id);
element.parentNode.removeChild(element);
}(#10850)
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Make a <div> disappear after x number of seconds
Lovely thanks - how do I assign the DIV to use that tho?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
