tags:

views:

165

answers:

6

i need to hide a div (like mail sent successfull in gmail)after certain time period when i reload the page ? any body please help me by giving codes..

+1  A: 

You may use setTimeout to delay a function's execution:

window.setTimeout(doSomething, 1000); // 1000ms == 1 second

To hide an element, you may set its display property to none:

var element = document.getElementById('foo');

function doSomething() {
    element.style.display = 'none';
}
moff
If I read him correctly, he wants persistence across page reloads.
Pekka
+2  A: 

Try this:

var timePeriodInMs = 4000;

setTimeout(function() 
{ 
    document.getElementById("myDiv").style.display = "none"; 
}, 
timePeriodInMs);
Tim S. Van Haren
If I read him correctly, he wants persistence across page reloads.
Pekka
Folks, don't waste your time on this question. See my comment to the question above.
Pekka
+1  A: 
setTimeout(function(){
   document.getElementById('messageID').style.display = 'none';
}, 5000);  //5secs
N 1.1
If I read him correctly, he wants persistence across page reloads.
Pekka
@Pekka: he says like gmail, in gmail, if we reload the page just after sending a mail, the "mail sent" notice does not persist.
N 1.1
@nvl true, but he also says `after certain time period when i reload the page ? `
Pekka
may be he missed " **or** " ? :)
N 1.1
<html><head><title>Untitled Document</title><script type="text/javascript" src="jquery-1.4.2.min.js"></script><script type="text/javascript"> /*$(document).ready(function(){ window.setTimeout(function(){ $('#deletesucess').hide(); }, 10000 /* delay time in milliseconds });*/setTimeout('$("#deletesucess").hide()',1500);</script></head><body><div id="deletesucess" >hiiiiiiiiiii</div></body></html> not working pekka
rag
Folks, don't waste your time on this question. See my comment to the question above.
Pekka
got solution guys:-stackoverflow.com/questions/2426304/how-to-hide-a-div-after-some-time-period.... thanks for your kind support. regards, rag
rag
A: 
  1. add jquery to your html document
  2. add script tag to head of your document containing:
<script type="text/javascript">
    $(document).ready(function(){
        window.setTimeout(function(){
            $('#id-of-div').hide();
        }, 10000 /* delay time in milliseconds */
    });
</script>
Kris
<html><head><title>Untitled Document</title><script type="text/javascript" src="jquery-1.4.2.min.js"></script><script type="text/javascript">$(document).ready(function(){$('#deletesucess').delay(1000).fadeOut();});//setTimeout('$("#deletesucess").hide()',1500);</script></head><body><div id="deletesucess" >hiiiiiiiiiii</div></body></html>i have tried this kris but not working
rag
@rag have you added JQuery to the document?
Pekka
That makes me think jquery didn't actually load for that page, or that your documents parse tree is somehow broken. what does the javascript console say? (firebug or webkit inspector available?)
Kris
One does not need a whole 26kb JQuery library to do this. What if he does not want a to use a library? What if he uses Mootools?
Jonathan Czitkovics
and tried ur $(document).ready(function(){ window.setTimeout(function(){ $('#id-of-div').hide(); }, 10000 /* delay time in milliseconds */ }); ------------->not working
rag
@Jonathan, then he should disregard my answer and go with another solution of the readily available ones.
Kris
Folks, don't waste your time on this guy. See my comment to the question above.
Pekka
Thats because he/she expects you to install JQuery just to do this.
Jonathan Czitkovics
/jqury/jquery-1.4.2.min.js:77Uncaught SyntaxError: Unexpected identifier and timehidediv.php:12Uncaught SyntaxError: Unexpected token } are the errors
rag
you have a typo somewhere before line 13 of the html output
Kris
Its because he made no mention of using JQuery so I don't see it as a valid answer.
Jonathan Czitkovics
got solution guys:-stackoverflow.com/questions/2426304/how-to-hide-a-div-after-some-time-period....thanks for your kind support.regards,rag
rag
A: 

You are looking at the setTimeout( expression, timeout ); where you need to give it an expression to run after the timeout in milliseconds that you allocate to it. then you would do element.style.display="none"

ex:

setTimeout( function(){element.style.display="none"}, 4000 );
Jonathan Czitkovics
+2  A: 

If you want the element to disappear after a certain time, regardless of page reloads (that's the way I read your question), you would have to work with cookies.

  • You would have to set a cookie with the starting point

  • You would have to execute a JavaScript function on page load that compares the time set in the cookie with the current time, and shows/hides the element accordingly.

  • For a perfect solution, you would additionally implement a timer that compares the current date to the date in the cookie every, say, half-second, and hides the element when the time has been reached.

Using a framework like JQuery is certainly a good idea for this.

Pekka
:)pekka pls give a solution.if anythng i need to clarify with my question pls ask me
rag
@rag it is rude in the *extreme* to open a question, receive *extensive* support there much beyond normal level, and then when no reaction comes for 20 minutes to open *the same question again*. You are showing zero respect for your fellow programmers' time and attention - most of whom have work to do - and you can be sure I will not be putting one minute into your questions again. Go learn it yourself.
Pekka
pekka i have tried it in javascript becuase i need to find eithr der should be solution..
rag
@rag then go and hire somebody to solve it for you.
Pekka
ok pekka i let me analyse those supports...thanks guys am leavng thanks pekka..
rag
rag