I am trying to make a function for changing the background image of a div every 6s with jQuery.
Here is what I have, but it doesn't work, doesn't even load first image.
Anyone could help me fix this please?
$(document).ready(function(){
var body = $(‘#main’);
var backgrounds = new Array(
‘url(../style/background.jpg)’,
‘url(../style/background2.jpg)’,
‘url(../style/background3.jpg)’
);
var current = 0;
function nextBackground() {
body.css(
‘background’,
backgrounds[current = ++current % backgrounds.length]
);
setTimeout(nextBackground, 6000);
}
setTimeout(nextBackground, 6000);
body.css(‘background’, backgrounds[0]);
});