//adding a 'x' button if the user wants to close manually $("#result").html('
'+info+'
'); //timing the alert box to close after 5 seconds window.setTimeout(function () { $(".alert").fadeTo(500, 0).slideUp(500, function () { $(this).remove(); }); }, 5000); //Adding a click event to the 'x' button to close immediately $('.alert .close').on("click", function (e) { $(this).parent().fadeTo(500, 0).slideUp(500); });