Very Simple Random Image

/ Published in: JavaScript
Save to your folder(s)

Extremely simple random image when using similar naming structure and a set number of images (eg. imagePrefix_1,jpg, imagePrefix_2,jpg, etc.)

Copy this code and paste it in your HTML
  1. <script type="text/javascript">
  2. var randomnumber = Math.floor(Math.random()*4)+1; // Start at 1 instead of 0
  3. document.write('<img src="imagePrefix_' + randomnumber + '.jpg" />');
  4. </script>

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.