How can a JavaScript statement be called after another has finished? The container element should only be removed from the DOM after the CSS transition is finished. Is this possible using callback functions, or would a custom event need to be created? It would be best to know how without the use of jQuery. Is it possible to do using ES5 without Promises?
var myContainer = document.getElementById("my-container");
myContainer.style.opacity = 1;
myContainer.style.transition = "opacity 1s";
var myButton = document.getElementById("myButton");
myButton.addEventListener('click', hideContainer);
function hideContainer() {
// Set container opacity to 0
myContainer.style.opacity = 0;
// Only execute once opacity has reached 0.
document.body.removeChild(myContainer);
}