In the finished document, I populate the variables and use them to start the for loop, which creates several divs with the box
class. I would like to add the possible
class to those box
divs randomly so that they are evenly distributed. For example, let's say that we end up with 100 divs with the box
class, I would like a random number of these divs to also have the possible
class.
Any ideas on how I can do this? I have included my current code below.
thanks
$(document).ready(function() { var wrapper = $('.wrapper'); var wrapperWidth = wrapper.width(); var wrapperHeight = wrapper.height(); var wrapperArea = wrapperWidth * wrapperHeight; var boxWidthHeight = 30; var boxArea = boxWidthHeight * boxWidthHeight; var boxCount = wrapperArea / boxArea; alert(boxCount); for(var i = 0; i < boxCount; i++) { $('.wrapper').append('<div class="box"></div>'); } });
source share