Seven circles but only one is changing colour, why?

前端 未结 8 1261
梦谈多话
梦谈多话 2021-01-26 09:29

I am new to javascript and I have an assignment to create seven circles which should change colour on a mouse click. The first circle is changing colour but the other six just r

8条回答
  •  暖寄归人
    2021-01-26 09:44

    Try it like this ` let circles = Array.from(document.querySelectorAll('circle'));

    circles.forEach((circle) =>{ circle.onclick = function () { color = colors.shift(); colors.push(color); circle.style.fill = color; } } `

    cheers

提交回复
热议问题