Below is a JavaScript file:
var ToastBtnClicks = 0;
function ShowToast(ToastText){
ToastBtnClicks++;
$('#ToastContainer').append("<div class='ToastContainerChild' id='ToastContainerChild"+ ToastBtnClicks +"'>"+ToastText+"</div><br>");
//document.getElementById("ToastContainer").className = "show";
setTimeout(function(){ $("#ToastContainerChild"+ToastBtnClicks).remove(); }, 2000);
}
Whenever the ShowToast function gets called, a new div element gets appended to the element #ToastContainer. That process is working perfectly. Also, after 2 seconds of calling the function, that new element gets removed using setTimeOut method. The problem I'm facing, is that if we call that function multiple times(without waiting for the rest to get removed), and after some seconds if we stop continuously calling that function, only the lastly appended element gets removed(after 2 secs). Why? I want the function to remove every appeded elements from the webpage, right 2secs after their creation(or appendation). How do I do it ? And sorry for my bad English, if it is...