Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery autohide element after 5 seconds

Is it possible to automatically hide an element in a web page 5 seconds after the form loads using jQuery?

Basically, I've got

<div id="successMessage">Project saved successfully!</div> 

that I'd like to disappear after 5 seconds. I've looked at jQuery UI and the hide effect but I'm having a little trouble getting it work the way I want it to.

<script type="text/javascript">         $(function() {             function runEffect() {                  var selectedEffect = 'blind';                  var options = {};                  $("#successMessage").hide(selectedEffect, options, 500);             };              $("#successMessage").click(function() {                 runEffect();                 return false;             });         });     </script> 

I'd like the click function to be removed and add a timeout method that calls the runEffect() after 5 seconds.

like image 557
Chris Conway Avatar asked Mar 25 '09 20:03

Chris Conway


People also ask

How to hide a div after 5 seconds in jQuery?

Select the div element. Use delay function (setTimeOut(), delay()) to provide the delay to hide() the div element.

How do you delete a div in 5 seconds?

You can use setTimeout like this: setTimeout(function(){ $('#divID'). remove(); }, 5000); The 5000 (ms) means 5 seconds.

How do I display a div for 5 seconds?

If it's not an animation, use setTimeout() directly, like this: $("#myElem"). show(); setTimeout(function() { $("#myElem"). hide(); }, 5000);


1 Answers

$('#selector').delay(5000).fadeOut('slow'); 
like image 181
justmeol Avatar answered Sep 21 '22 21:09

justmeol