Two issues that I spot:
When working with indexes, the index starts at zero, not one.
.children(\[selector\])
does not take an index, it takes a selector. So you are asking jQuery to find the element of type of one. Instead use .eq(index)
to get the element.
So the changes to your code would be:
var i = 0;
var id = setInterval(function () {
$("ul").children().eq(i).toggleClass('test');
i++;
if (i === 4) {
i = 0;
}
}, 1000);
Better yet, move the selecting out so you are not doing the querying of the DOM every iteration
var i = 0,
lis = $("ul").children(),
id = window.setInterval( function () {
lis.eq(i).toggleClass('test');
i++;
if (i === 4) {
i = 0;
}
}, 1000);