I'm trying to create an Etch-A-Sketch using a grid of boxes created from div elements, but the code handling the highlighting of the boxes (mouseenter method) is not working. However, it works when the code is placed in the console, so I am confused as to what is causing the problem.
<script>
$('button').click(function() {
$('#container').empty();
var row = prompt("How many rows are desired?");
var col = prompt("How many columns are desired?");
for (var j=0; j<=row; j++) {
for (var i=0; i<=col; i++) {
$('#container').append('<div class="grid-box"></div>');
};
$('#container').append('<div class="next-row"></div>');
};
$('.grid-box').mouseenter(function() {
$(this).css('background-color', "red");
});
});
</script>
Any help would be much appreciated!