I am trying to change a grid of small square divs to a random background color. As far as I can tell my syntax is correct and the console is not throwing any errors but it's like the .css() will not accept my genColor method.
I found this which is very similar but the solution offered has not seemed to work.
function genColor() {
'use strict';
var hexes = '0123456789ABCDEF'.split('');
var color = '#';
for (var i = 0; i < 6; i++){
color += hexes[Math.floor(Math.random * 16)];
}//end for loop
return color;
which is used in this
function highlightSquare() {
'use strict';
$('.square').on('mouseenter', function () {
$(this).css('background', genColor());
});
Please help I can't figure out why this isn't working when examples show me it should.
P.S. The 'use strict'; keeps the Brackets editor JSLint from yelling at me. As near as I can tell it does not affect the code above.
alert(color);right before the return to ensure it's running and generating a valid color. From what it looks like, your event listener is within the highlightSquare function - where it should probably not be within a function (aside from$(document).load(function(){ });).