Whenever we submit a form or do some task, we usually display a success message, but sometimes it is required to hide this message automatically after some time period. 
We can do this by two ways:
- By using setTimeout method:
<html> 
  <head> 
    <title>Demo</title> 
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript"> 
      $(function(){
    setTimeout(function(){
        $("#alertMessage").hide();
        }, 2000);
      });
    </script>
  </head> 
  <body> 
    <div id="alertMessage" > This is alert message. </div> 
  </body> 
</html>
- By using delay() and fadeOut() methods:
<html> 
  <head> 
    <title>Demo</title> 
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript"> 
      $(function(){
       $('#alertMessage').delay(2000).fadeOut();
      });
    </script>
  </head> 
  <body> 
    <div id="alertMessage" > This is alert message. </div> 
  </body> 
</html>
Hope this will help you:)
                       
                    
1 Comment(s)