I'm trying to make a background effect. On keypress it creates a div with that fades out after half a second. Every time a key is pressed, it creates a new div with a new id. How do I remove each div half a second after it was triggered?
I forgot to mention, I have a function that shortens document.getElementById('id') to $('id'). I'm not using jQuery.
Here's my code so far.
function $(e) {
return document.getElementById(e)
}
let circles = 0;
onkeypress = () => {
document.body.insertAdjacentHTML('beforeend', `<div class="effect" id="l${circles}"></div>`)
setTimeout(function(){
$(`l${circles}`).remove()
},500)
circles++
}