Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
window.notify = function(message, type = "info", duration = 4000) { const colors = { success:"#198754", danger:"#dc3545", warning:"#ffc107", info:"#0dcaf0" }; const $toast = $(`<div class="toast-notification" role="alert" aria-live="assertive">`) .css({ background: colors[type], color:"#fff" }) .text(message) .appendTo("#toast-container") .fadeIn(200); const timer = setTimeout(() => $toast.fadeOut(200, () => $toast.remove()), duration); $toast.on("click", () => { clearTimeout(timer); $toast.fadeOut(200, () => $toast.remove()); }); }; notify("Saved successfully!", "success"); notify("Something went wrong.", "danger", 0); // persistent
Result
Open