Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide div after a few seconds

I was wondering, how in jquery am I able to hide a div after a few seconds? Like Gmail's messages for example.

I've tried my best but am unable to get it working.

like image 611
James Avatar asked May 04 '09 17:05

James


1 Answers

This will hide the div after 1 second (1000 milliseconds).

setTimeout(function() {      $('#mydiv').fadeOut('fast');  }, 1000); // <-- time in milliseconds
#mydiv{      width: 100px;      height: 100px;      background: #000;      color: #fff;      text-align: center;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div id="mydiv">myDiv</div>

If you just want to hide without fading, use hide().

like image 182
swilliams Avatar answered Sep 28 '22 15:09

swilliams