Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fade out message after 10 seconds, clearing the input elements using jQuery

I'm displaying a message (#final_msg) after the user submits the form. What I want to do is that, after 15 seconds, the message (#final_msg) should fade out, clearing away [or fading out] the text in the input elements as well. Is it possible to do this?

else {
                        //create post data
                      var postData = { 
                        "name" : $("#name").val(),
                        "email" : $("#email").val(),
                        "msg" : $("#msg").val(),
                        "origin" : $("#origin").val()
                      };

                      //make the call
                      $.ajax({
                        type: "POST",
                        url: "test.php",
                        data: postData, //send it along with your call
                        success: function(response){
                            $('#final_msg').fadeIn();

                        }
                      });
                }
like image 585
input Avatar asked Aug 15 '10 17:08

input


People also ask

How do I fadeOut text in jQuery?

The jQuery fadeOut() method is used to fade out a visible element. Syntax: $(selector). fadeOut(speed,callback);

How do I display a div for 5 seconds?

If it's not an animation, use setTimeout() directly, like this: $("#myElem"). show(); setTimeout(function() { $("#myElem"). hide(); }, 5000);

What is the use of fadeOut in jQuery?

jQuery Effect fadeOut() Method The fadeOut() method gradually changes the opacity, for selected elements, from visible to hidden (fading effect). Note: Hidden elements will not be displayed at all (no longer affects the layout of the page). Tip: This method is often used together with the fadeIn() method.

What is fadeIn and fadeOut in jQuery?

jQuery has 2 fading methods which are . fadeIn() and . fadeOut(). The fadeIn method displays the element by fading it to opaque. The fadeOut method hides the element by fading it to transparent.


1 Answers

If you're on jQuery 1.4, you can use the delay function:

$('#final_msg').fadeIn().delay(10000).fadeOut();
like image 144
Benjamin Wohlwend Avatar answered Sep 26 '22 05:09

Benjamin Wohlwend