Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to hide a message after some time interval with jQuery?

    • 0
    • 1
    • 0
    • 1
    • 1
    • 0
    • 0
    • 0
    • 6.24k
    Comment on it

    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:

    1. 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>
    

    1. 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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: