'jQuery show for 5 seconds then hide

I'm using .show to display a hidden message after a successful form submit.

How to display the message for 5 seconds then hide?



Solution 1:[1]

You can use the below effect to animate, you can change the values as per your requirements

$("#myElem").fadeIn('slow').animate({opacity: 1.0}, 1500).effect("pulsate", { times: 2 }, 800).fadeOut('slow'); 

Solution 2:[2]

Just as simple as this:

$("#myElem").show("slow").delay(5000).hide("slow");

Solution 3:[3]

To show error message of 5 sec using ajax that is save in session in laravel 8

<div id="error">
    @php
        $error = Session::get('message');
        echo $error;
    @endphp
</div>
<script>
    $("#error").show();
    setTimeout(function() {
        $("#error").hide();
    }, 5000);
</script>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rahul
Solution 2 Antonio Ooi
Solution 3