My CSS includes a base class named "toast" that contains basic styling, along with a JavaScript function that generates different types of toasts based on user input. The function modifies the toast class by inserting icons and text as demonstrated below:
#toast {
visibility: hidden;
width: 200px;
min-height: 40px;
max-height: 100px;
border-radius: 5px;
//various other styling properties
}
Here is the JavaScript code:
function showToast(type) {
var label = null;
var iconElement = null;
var i = document.getElementById("toast")
switch (type) {
case 'success':
i.style.border = 'solid 1px #007700';
label = "SUCCESS";
iconElement = "icons/success.png";
break;
//additional cases for other types
}
document.getElementById("title").innerHTML = label;
document.getElementById("icon").src = iconElement;
i.style.visibility = 'visible';
}
Currently, each time I call the function to create a new toast, it replaces the existing one. However, I want to be able to stack multiple toasts and display multiple feedback messages simultaneously. How can I create multiple instances of my CSS class so that they are not overwritten each time the constructor is called?