javascript - Setting a the background image of a div from an array -
i have make div , set background image array of images, , make 2 buttons change picture next image in array, or previous image of array. i've been looking around stackoverflow , w3 schools, don't know why it's not working.
var backgroundimage = new array(); backgroundimage[0] = "np.jpg"; backgroundimage[1] = "putin.png"; backgroundimage[2] = "fob.jpg"; function nextimage() var img = document.getelementbyid(element); for(var = 0; < backgroundimage.length;i++) for(var = 0; < backgroundimage.length;i++) { document.getelementbyid(element).src = [0].src; document.style.backgroundimage="url(backgroundimage[0])"; }
you not evaluating array, creating literal want
document.style.backgroundimage="url(" + backgroundimage[0] + ")";
Comments
Post a Comment