Automatically close alert message on Twitter Bootstrap

Posted on March 16, 2014 at 10:40 pm

Automatically close (fade away) the alert message after 5 seconds:

<script type="text/javascript">
<!--
 
$(document).ready(function () {
 
window.setTimeout(function() {
    $(".alert").fadeTo(1500, 0).slideUp(500, function(){
        $(this).remove(); 
    });
}, 5000);
 
});
//-->
</script>

The content below the message will slide-up to its original position.

This is the HTML code used to display the message:

<div class="alert alert-danger">
This is an example message...
</div>

More information:
window.setTimeout(function, delay)

Updated on March 20, 2014 at 12:13 am

Receive updates via email

Other Posts

Updated Posts