srikanth_naalla srikanth_naalla -5 years ago 268
HTML Question

Bootstrap Alert Auto Close

My need is to call alert when I click on Add to Wishlist button and should disappear the alert in 2 secs. This is how I tried, but the alert is disappearing instantly as soon as it is appearing. Not sure, where the bug is.. Can anyone help me out?

JS Script

$(document).ready (function(){
$("#myWish").click(function showAlert() {
window.setTimeout(function () {
$("#success-alert").alert('close'); }, 2000);

HTML Code:

<div class="product-options">
<a id="myWish" href="" class="btn btn-mini" >Add to Wishlist </a>
<a href="#" class="btn btn-mini"> Purchase </a>

Alert Box:

<div class="alert alert-success" id="success-alert">
<button type="button" class="close" data-dismiss="alert">x</button>
<strong>Success! </strong>
Product have added to your wishlist.

Answer Source

For a smooth slideup:

$("#success-alert").fadeTo(2000, 500).slideUp(500, function(){


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