I am having problems understanding how a loop works how can I make a 'for' loop infinite times.
I am developing a wordpress website and I am using an automatic slider, in which the first slider element gets a class of "current" and I want a looping function that keeps verifying which element is the first one for me to be able to display certain texts for each slide.
The code is not that important but this is the JS:
window.onload = function() {
console.log('test');
const frank = document.querySelectorAll('#franck');
const slide21 = document.getElementById('slick-slide21');
console.log(slide21);
if(slide21.classList.contains('slick-current')){
console.log('julien');
}
and the html for current slider elements looks like this:
<div data-slick-index="5" aria-hidden="false" style="width: 374px;" tabindex="0" role="tabpanel" id="slick-slide25" aria-describedby="slick-slide-control25">
I am checking if the element contains the Slide-current element but it checks only once. I have a for but can I make it check for every slide that moves at every 2 seconds?
Looping to 9999 or anything like it but i want an infinite loop.
CodePudding user response:
infinite for loop:
for(;;) {
/*things to do infinitely*/
}
in while loop:
while(1) {
/*things to do*/
}
and if you want to stop the loop, you can just add
if(/*condition to stop*/) {
break;
}