I am trying to select elements in the loop and pass them to setTimeout.
Why doesn't the following work as it is supposed to?
Is it because el.querySelector('.b') is slower than setTimeout?
var ids = document.querySelectorAll('.a'),
span
ids.forEach(el => {
span = el.querySelector('.b')
setTimeout(function() {
span.classList.add('visible');
}, 20, span);
})
.visible{
color:red;
}
<p class="a"><span class="b">1</span></p>
<p class="a"><span class="b">2</span></p>
<p class="a"><span class="b">3</span></p>