I am kind of trying to make a slot machine. To create slot machine affect i'am removing first div from the wrapper and adding it back to the bottom. onClick events works fine when i am using a value of 1000ms but when i use something like 100ms interval then i need to click multiple times rapidly for it to register click events. Why this behavior?
Also on touch screen (Checked on my mobile) i don't encounter this issue.
setInterval(function() {
swap_box();
}, 100);
function swap_box() {
let first_box = document.getElementsByClassName("box")[0];
first_box.remove();
document.getElementsByClassName("div-wrapper")[0].appendChild(first_box);
first_box.addEventListener("click", function() {
console.log(this.innerText);
});
}
.box {
width: 100px;
height: 50px;
border: 1px solid black;
}
<div class="div-wrapper">
<div class="box">0</div>
<div class="box">1</div>
<div class="box">2</div>
<div class="box">3</div>
<div class="box">4</div>
<div class="box">5</div>
<div class="box">6</div>
<div class="box">7</div>
</div>