Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

show div for a set time, then hide it

Im using jquery for various things on my site, but one thing im not sure how to do, is have it show an element, then wait X seconds, and hide the element.

$('#form').ajaxForm(function() { 
    $('#cartcontents').fadeOut("fast").load('cart.php').fadeIn("fast");
}); 

That's the JavaScript that I'm using now. How could I have it (when the form submits) display the div #notice for 5 seconds, then fadeOut?

like image 743
mrpatg Avatar asked Dec 09 '09 10:12

mrpatg


2 Answers

$('#form').submit(function() {
   $('#notice').show();
   setTimeout(function() { 
       $('#notice').fadeOut(); 
   }, 5000);
});
like image 52
Jacob Relkin Avatar answered Oct 11 '22 12:10

Jacob Relkin


in the onSubmit event handler make the div appear by using $('#divName').show() (i think thats correct syntax). The you can use setTimeout("hideDiv()",5000), you then define hideDiv() which is a new function which does $('#divName').fadeOut()

like image 32
Aly Avatar answered Oct 11 '22 12:10

Aly