Show div for given time, then hide it

I use jquery for different things on my website, but one thing I'm not sure how to do is show the element and then wait X seconds and hide the element.

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

This is the JavaScript I'm using now. How can I get it (when the form is submitted) displays the #notice div for 5 seconds, then fadeOut ?

+7
javascript jquery
source share
2 answers
 $('#form').submit(function() { $('#notice').show(); setTimeout(function() { $('#notice').fadeOut(); }, 5000); }); 
+15
source share

in the onSubmit event onSubmit make a div using $('#divName').show() (I think this is the correct syntax). You can use setTimeout("hideDiv()",5000) , then you define hideDiv() , which is a new function that does $('#divName').fadeOut()

+3
source share

All Articles