ga-wdi-exercises / pixart_js

Use JS events and programmatically generated DOM elements to build a drawing application. [javascript, dom]
MIT License
9 stars 321 forks source link

w07d02 homework #28

Closed keithknox closed 9 years ago

keithknox commented 9 years ago

completeness: 2.5-3ish comfort: same.

i got stuck trying to create a click event for the squares. I thought following the same pattern for setting the brush would work but the change would be iterating over the squares. it didn't work out.

RobertAKARobin commented 9 years ago

Give this a whirl:

var squares = document.querySelectorAll(".square");
for(var x = 0; x < squares.length; x++){
  var square = squares[x]; // This gives you the current square element
  square.addEventListener("mouseover", function(){
  });
  square.style.backgroundColor = "whatever";
}

Many other people got stuck on the same thing!