I am trying to change the source of an image after a delay of two seconds. I am changing the source, waiting for two seconds and then changing it back to another random image. This is my function:
function ChangeToBomb() {
var aantalPionnenOpScherm = $('#depionnen img')
var randomPion = Math.floor(Math.random() * aantalPionnenOpScherm.length);
var randomBom = Math.floor(Math.random() * bombs.length);
$('#depionnen img:nth-child(' + randomPion + ')').fadeOut(100, function() {
$(this).attr('src', bombs[randomBom]).fadeIn(100).delay(2000)
$(this).fadeOut(100)
$(this).attr("src", pictures[randomPion])
})
}
It works until:
$(this).fadeOut(100)
Does someone know a solution?