Array.prototype.forEach.call(document.getElementsByName('cv10[]'), function(el) { el.onchange = function() { el.parentNode.style.backgroundColor = (el.parentNode.style.backgroundColor === 'red') ? '#fff' : 'red'; }; });