-1

I created an etch-a-sketch type of program so that when a user enters a height, width, and select a color choice, they are able to draw on the provided grid below. I am having troubles with the drawing part. I included a link to my code via codepen ... Online 37, I created a mouseover event but I can't figure out why it won't work. Any feedback would be greatly appreciated.

   $("#pixelCanvas td").on("mouseover",  function(){
   var colorPicker = $("#colorPicker").val();
   $( this ).css("background-color",colorPicker );
   });

  https://codepen.io/unicorn1/pen/JpVmZV 
  • 1
    Please include the code from your external source in the question here on Stack Overflow. Also explain what is meant be "won't work". See [mcve] and [ask]. – Heretic Monkey Mar 04 '18 at 21:19
  • You might take a look at https://ux.stackexchange.com/questions/106380/what-is-the-difference-between-a-mouseover-and-a-hoverover/106382 – Jtbs Mar 04 '18 at 21:20
  • Possible duplicate of [when to choose mouseover() and hover() function](https://stackoverflow.com/questions/17589420/when-to-choose-mouseover-and-hover-function) – Erik Philips Mar 04 '18 at 22:25

2 Answers2

0
$("#pixelCanvas").on("mouseover", "td", function(){
  var colorPicker = $("#colorPicker").val();
  $(this).css("background-color", colorPicker);
});

Your td are being dynamically genererated, your #pixelCanvas exists from start, so you want to put an eventListener on the #pixelCanvas, but you only want it to react if a td is actually clicked. Since the #pixelCanvas existed from the start it will know if there happened something inside of it's container, while i generated td wouldn't know that it was supposed to have an eventListener

Pavlo
  • 1,157
  • 7
  • 13
-1

I think this discussion shows you the main differences between mouseover and hover. Here is the link to it (when to choose mouseover() and hover() function

  • 1
    [When someone goes on Stack Overflow, the question "answer" should actually contain an answer. Not just a bunch of directions towards the answer.](https://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links-elsewhere-really-good-answers). – Erik Philips Mar 04 '18 at 22:24