I have a total of 20 divs and three different hover effect classes. I would like to randomly assign one of these three hover effects to each div.
The JavaScript code I am using is:
<script>
$(document).ready(function () {
viewClasses = 3;
randomNumber = Math.round(Math.random() * (viewClasses - 1)) + 1;
$('.basediv').each(function(i, val) {
$(this).addClass('view' + randomNumber);
});
});
</script>
All my div elements have the class .basediv assigned to them
and there are CSS classes named: .view1 .view2 .view3
With the current code, all div elements end up with the same hover effect. Each div element gets either the .view1, .view2, or .view3 effect at random.
I would appreciate any guidance on this matter