I leave a version that does not use jQuery. What I'm trying to do is insert an image randomly in body
, in this example there are 10 png images, with name from 0 to 9, the image changes every 1 second, so I put 1000
as an argument to setTimeout, every second It's equivalent to a thousand milliseconds.
This is optional, but it's good, the script file and the HTML should be in the format UTF-8
so that you can include accents (á í í ú ú), in my example, the name of the variable cantidadImágenes
carries the tilde á.
I did not try the code but it should work, only if the images exist relatively to the site.
function imagenAleatoria()
{
var elemento=document.body
var cantidadImágenes=10
var aleatorio=Math.floor(Math.random()*cantidadImágenes)
elemento.innerHTML="<img src=\""+aleatorio+".png\"></img>"
setTimeout(imagenAleatoria,1000)
}
imagenAleatoria()