Hey, I have just started scripting JavaScript and I got stuck when I wanted to change everytime the page is reloaded to have a new image.
Here is my current script:
It displays the first image. However, it doesn't change every-time to a new one.Code:var index = 1; function randomContent() { var mainContent = document.getElementById("mainContent"); var randomImg="images/content" + index++ + ".png"; mainContent.src=randomImg; } window.onload = function() { // Load Random Images randomContent(); }


Reply With Quote
Bookmarks