Q:

Add click on every child one by one

I have a slider which has no auto scroll, so I need a jquery function to add auto scroll on the slider. these are the slider indicator, which changes the slides.
<div class="slider__navi">
<a href="#" class="slide-nav" data-slide="1">pikachu</a>
<a href="#" class="slide-nav" data-slide="2">piplup</a>
<a href="#" class="slide-nav" data-slide="3">blaziken</a>
<a href="#" class="slide-nav active" data-slide="4">dialga</a>
</div>

I am doing it with setInterval like:
setInterval(function(){
for (var i = 1 ; i <= 4; i++) {
$('.slide-nav:nth-child(' + i +')').click();
} 
},1000)

but it is not right, I want to click each slide-nav one by one, or add active class one by one by waiting some time.

A:

  $(function(){
      $('.slide-nav').click(function(){
          $('.active').removeClass('active');
          $(this).addClass('active');
      });
      let currentLink = 1;
      let linkLengths = $('.slide-nav').length;
      setInterval(function(){
          $('.slide-nav:nth-child(' + currentLink++ +')').click();
          if(currentLink == linkLengths+1 ){
              currentLink = 1;
          }
      }, 1000)
});

This should do it. https://jsfiddle.net/msvqyhrd/

