function showToast(message, duration) { // Create a new div element for the toast message const toast = document.createElement('div'); toast.classList.add('toast'); // Add the message content to the toast toast.innerHTML = message; // Add the toast to the container element const container = document.getElementById('toast-container'); container.appendChild(toast); // Use a timer to remove the toast after the specified duration setTimeout(() => { container.removeChild(toast); }, duration); }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter