I have four divs where the first div has a class "selected". I would like to remove that class and append it to the next div number two after 2000 milliseconds. But then after another 2000 milliseconds i need that class to be removed and to be appended to the div number 3 and so on. But this does not work. any clues?
JavaScript
var sel = "";
function aaa() {
$('#holder > div').each(function () {
var isSelected = $(this).hasClass("selected");
if (isSelected) {
var selectedId = $(this).attr('id');
console.log(selectedId);
$(this).removeClass("selected");
$("#" + selectedId).next().addClass("selected");
}
});
}
setInterval(aaa, 5000);
HTML
<div id="holder">
<div id="one" class="selected"></div>
<div id="two"></div>
<div id="three"></div>
<div id="four"></div>
</div>