简体   繁体   中英

Javascript infinite loop for If Statement

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 class="premium-carousel-template item-wrapper slick-slide slick-current slick-active" 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.

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM