You can create a method and use setInterval
, see:
let li = document.querySelectorAll('li');
let x = 0;
let intervalo = null;
const loop = () => {
if (x < li.length) {
console.log(li[x].innerText);
} else {
clearInterval(intervalo);
console.log('Fim !');
x = 0;
}
x++;
};
intervalo = setInterval(loop, 1000);
<li>Texto A</li>
<li>Texto B</li>
<li>Texto C</li>
<li>Texto D</li>
<li>Texto E</li>
<li>Texto F</li>
<li>Texto G</li>
<li>Texto H</li>
<li>Texto I</li>
Every 1 second the method loop
which will check whether the variable’s value x
is less than the amount of elements li
in the document, if it is, returns in the console the text of that element.
I’m a typing slug :).
– NoobSaibot