I've been trying to change color of these divs through a click of a button. But I've been unable to select the EVEN divs like in CSS -> nth-child(even).
Help me select oonly even divs with class name 'newBox'. Thank You
const mainContainer = document.querySelector('.main_box');
for (let i = 0; i < 10; i++) {
const newBox = document.createElement('div');
newBox.classList.add('newBox');
mainContainer.appendChild(newBox);
}
function change() {
//I want here to select only the even divs
document.querySelectorAll('.newBox').forEach((divs) => {
divs.style.backgroundColor = "green";
})
}