Simple two line Image Randomiser Script with jQuery

Written on 02/05 • 0 Comments

It's a common task adding a random header or banner for each page view. If you are already utilizing the jQuery library you can add just two lines or if not you have a few more lines to get the job done.

The above shows an example the script in action. Reload the page and a random image will be loaded.

1. Start with an array of images.

Change the image filenames in the array to the actual filenames. There is no need to add the file path; we’ll do that in a moment.

var images = ['image1.jpg', 'image2.jpg', 'image3.jpg', 'image4.jpg', 'image5.jpg'];

Continue Reading

More articles can be found in the archives, feel free to have a look around and leave your comments.

Save a massive 36% on a subscription to .net magazine!

We love .net magazine (known as "Practical Web Design" outside the UK) and have teamed up with Future Publishing to get our readers up to a massive 36% off a years subscription.