How does js add a separate class? to the li loop every 1 second

  1. add a separate class= "active" to li every second, and the rest is empty.
  2. wait a second to pass, the first li is empty, the second li adds class= "active", and so on.

HTML:

<ul id="new">
    <li><img src="img/01.jpg" ></li>
    <li><img src="img/02.jpg" ></li>
    <li><img src="img/03.jpg" ></li>
    <li><img src="img/04.jpg" ></li>
    <li><img src="img/05.jpg" ></li>
    <li><img src="img/06.jpg" ></li>
</ul>

js:

    var temp = document.getElementById("new");
    var li = temp.getElementsByTagName("li");

    setInterval(function(){           
    for(var i = 0; i<li.length; iPP){
                           
                 // 
                 li[i].className="active";     
                       
    //1                   
    },1000);
          
Mar.16,2021

changed it on your basis

    var temp = document.getElementById("new");
    var li = temp.getElementsByTagName("li");
    var i = 0;
    setInterval(function () {
        li[i].className = "active";
        if(i-1>=0){
          li[i-1].className = "";
        }else{
          li[li.length-1].className = "";          
        }
        iPP;
        if(i==li.length){
          i=0
        }  
    },1000);

well, this idea

var temp = document.getElementById("new")
setInterval(function () {
    var current = temp.getElementsByClassName('active')
    var li = temp.getElementsByTagName('li')

    if (current.length == 0) {
        li[0].className='active'
    } else {
        var index = Array.prototype.indexOf.call(li,current[0])
        current[0].className=''
        target = li.length-1 < index ? 0 : index+1
        li[target].className='active'
    }

},1000);
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3bfd2-2b824.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3bfd2-2b824.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?