I am having trouble with a seemingly simple Jquery function.
Basically, the small/med/big etc. buttons create a grid of >div>s within a >div>. They all have a class of .colorblock I want to add a class or change the background color upon hovering over these divs.
I've included the jsfiddle (but I'm creating this on my own computer - ignore the fact that the button box butts into the grid on jsfiddle, I can fix that...eventually), and copied the 'problem areas' below. The grid is created successfully, but I can't get anything to interact with the <\div class="colorblock"> after that.
https://jsfiddle.net/pqtn50fc/4/
Also - is there a way to use a variable defined earlier in jQuery directly in the
.append('<div style="height: jVARIABLE"> </div>')
? It's simpler to calculate the size and put it in the loop instead of making different loops for each div. I tried changing all the divs after they were created but it kept lagging/freezing.
HTML____________
<div id="colorspace">
</div>
CSS____________
.colorblock {
float: left;
outline: 2px solid blue;
}
.black {
background-color: black;
}
.smallcolorblock {
width: 21.875px;
height: 21.875px;
}
JQUERY____________
var smallH = '<div class="smallcolorblock colorblock"></div>'
$('#small').click(function(){
$('.colorblock').remove();
for (var i = 1; i <= 32*32 ; i++) {
$('#colorspace').append(smallH);
};
$('.colorblock').hover(function(){
$(this).css("background", getRandomColor()),
function(){
$(this).css("background", "white");
};
$('.colorblock').hover(function() {
$(this).addClass("black");
});