Seven circles but only one is changing colour, why?

前端 未结 8 1264
梦谈多话
梦谈多话 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:52

    In the onclick function pass the element itself using this keyword. It works in this case but remember it is wrong to give same id to more than 1 element. It should be unique.

    var circle = document.getElementById("circle1");
    
    
    colors = ['orange', 'yellow', 'green', 'blue', 'indigo', 'violet'];
    function a(e)
    
    {
      color = colors.shift();
      colors.push(color);
    
      e.style.fill = color;
    }
    
    
      

    Rainbow Colours

提交回复
热议问题