I’m trying to make a a JS forEach loop that is supposed to run after the DOM is fully loaded, but for some reason it won’t run on code but when I put the same loop on console it runs fine.
window.onload = (event) => {
var checkboxes = document.getElementsByName("plates")
var labelPlate = document.getElementsByName("labelPlate")
checkboxes.forEach((i, index) => {
if (i.checked) {
labelPlate[index].classList.add("active")
} else {
labelPlate[index].classList.remove("active")
}
})
};
Loop is supposed to run.