/ Published in: JavaScript
Extremely simple random image when using similar naming structure and a set number of images (eg. imagePrefix_1,jpg, imagePrefix_2,jpg, etc.)
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<script type="text/javascript"> var randomnumber = Math.floor(Math.random()*4)+1; // Start at 1 instead of 0 document.write('<img src="imagePrefix_' + randomnumber + '.jpg" />'); </script>