¿Cómo ocultar un div después de algún período de tiempo?


Necesito ocultar un div (como "mail sent successful" en Gmail) después de un cierto período de tiempo cuando recargue la página.

¿Cómo puedo hacer eso?

Author: Benjamin W., 2010-03-11

3 answers

Aquí hay un ejemplo de trabajo completo basado en sus pruebas. Compáralo con lo que tienes actualmente para averiguar dónde vas mal.

<html> 
  <head> 
    <title>Untitled Document</title> 
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript"> 
      $(document).ready( function() {
        $('#deletesuccess').delay(1000).fadeOut();
      });
    </script>
  </head> 
  <body> 
    <div id=deletesuccess > hiiiiiiiiiii </div> 
  </body> 
</html>
 90
Author: rosscj2533,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-03-11 16:30:26

En versiones anteriores de jquery tendrás que hacerlo de la "manera javascript" usando settimeout

setTimeout( function(){$('div').hide();} , 4000);

O

setTimeout( "$('div').hide();", 4000);

Recientemente con jquery 1.4 se ha añadido esta solución:

$("div").delay(4000).hide();

Por supuesto, reemplace "div" por el elemento correcto usando un selector jquery válido y llame a la función cuando el documento esté listo.

 43
Author: marcgg,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:02:13
setTimeout('$("#someDivId").hide()',1500);
 8
Author: Jage,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-03-11 15:40:28