else if (event.target.name = 'formStyleCheckbox') {
как лучше назначать ивенты, на каждый конкретный нужный элемент или на все вместе как в моем случае?
n = (n+1) mod 3, где три = количество цветов в цикле; а mod = остаток от деления.
const el = document.querySelector('#box');
const colors = [ 'red', 'green', 'blue' ];
let index = -1;
el.addEventListener('mouseenter', function() {
index = (index + 1) % colors.length;
this.style.backgroundColor = colors[index];
});
el.addEventListener('mouseleave', function() {
this.style.backgroundColor = '';
});