$(function () { var num = Math.ceil(5 * Math.random()); $('div.mv').addClass('background' + num); });