function removeToast(e) { //First we need to prevent default // to evade any unexpected behaviour e.preventDefault(); //After that we add a class to our toast (.single-toast) e.target.parentNode.parentNode.classList.add("fade-out"); //After CSS animation is finished, remove the element setTimeout(function() { e.target.parentNode.parentNode.parentNode.removeChild(e.target.parentNode.parentNode) }, 500); }