I had a question about switching classes using jQuery. In my case, I have 4 hyperlinks in the list. I want the following:
In the initial state, my first hyperlink received the class: "active":

But after a while I want the "active" class to be removed from hyperlink 1 and added to link2. The same process is also for hyperlinks 3 and 4.
So there is always one hyperlink that gets a black background color:

Another requirement is that whenever he reaches the last hyperlink (link 4), he must start again with link 1.
How can i do this? This is what I have so far: https://jsfiddle.net/f6ktje52/1/
HTML
<ul class="tab-slide">
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 2</a></li>
<li><a href="#">Link 3</a></li>
<li><a href="#">Link 4</a></li>
</ul>
JQuery
$(function() {
$('.tab-slide li').first().addClass('active');
setInterval(function() {
$('.tab-slide li').next('li').addClass('active');
}, 1000);
});
source
share