You can achieve this via setTimeout, querySelector and css transition
document.querySelector('.curtain').addEventListener('click', function(e) {
let f = document.querySelector('.fadeout')
setTimeout(function() {
f.classList.add('fade')
}, 500);
setTimeout(function() {
f.parentNode.removeChild(f)
}, 3500);
});
.fadeout {
opacity: 1;
transition: all 3s;
background-color: #f00;
color: #fff;
padding: 20px;
}
.fade {
opacity: 0
}
<div class="fadeout">Test fade</div>
<button class="curtain">click me</button>
12
solved Need help changing from jquery to vanilla javascript