jQuery simple alert message that fades out after N seconds

Posted on June 10, 2018 at 3:41 pm

Sample code to show an alert message and remove it (fade out) after N seconds.

This is the code to insert inside script tag:

$(document).ready(function () {
window.setTimeout(function() {
    $(".alert-message-simple").fadeTo(1500, 0).slideUp(500, function(){
        $(this).remove(); 
    });
}, 4000);
 
});

And then you can write your message inside:

<div class="alert-message-simple">
<p class="text-danger">Sample alert message goes here</p>
</div>

Receive updates via email

Other Posts

Updated Posts