function showAlert(message, type, appendto, closeDelay) { var alert = ""; var $cont = $("#" + appendto); //if ($cont.length == 0) { // // alerts-container does not exist, create it // $cont = $('
') // .appendTo($("#divMsg")); //} // default to alert-info; other options include success, warning, danger type = type || "info"; switch (type) { case "success": alert = $('
').addClass("fade in show alert alert-" + type) .append($('').append("×")).append("Success! ").append(" ").append(message); break; case "danger": alert = $('
').addClass("fade in show alert alert-" + type) .append($('').append("×")).append("Error!").append(" ").append(message); break; case "warning": alert = $('
').addClass("fade in show alert alert-" + type) .append($('').append("×")).append("Warning! ").append(" ").append(message); break; default: alert = $('
').addClass("fade in show alert alert-" + type) .append($('').append("×")).append("Note! ").append(" ").append(message); break; } // add the alert div to top of alerts-container, use append() to add to bottom $cont.prepend(alert); // if closeDelay was passed - set a timeout to close the alert if (closeDelay) window.setTimeout(function () { alert.alert("close"); }, closeDelay); }