Max Scho Max Scho -4 years ago 83
jQuery Question

How to open bootstrap alert automatically after a given time frame?

I need your help:

I am trying to display a bootstrap alert at the bottom-right of the
page automatically, 5 seconds after loading the site.

How can I achieve this. I tried my best, but I have not been able to make it work.

I would greatly appreciate your help.

Answer Source

I've done the work for you with this jsFiddle

HTML:

<div class="alert alert-success" id="myAlert">
     Hello World!
</div>

CSS:

#myAlert
{
  display: none;
  position: fixed;
  bottom: 0;
  right: 0;
  width: 33%;
  margin: 20px;
}

Javascript:

setTimeout(function(){ 
    $('#myAlert').fadeIn('slow'); 
}, 5000);

Make sure you put the javascript at the bottom of your page just before the closing tag (and wrap it with tags

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download