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.
Select the div element. Use delay function (setTimeOut(), delay()) to provide the delay to hide() the div element.
You can use setTimeout like this: setTimeout(function(){ $('#divID'). remove(); }, 5000); The 5000 (ms) means 5 seconds.
If it's not an animation, use setTimeout() directly, like this: $("#myElem"). show(); setTimeout(function() { $("#myElem"). hide(); }, 5000);
$('#selector').delay(5000).fadeOut('slow');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With