You need to run your code after the DOM is loaded. Either move it to after the </body> tag, or run it in the window.onload handler.
Also, your assignment statements need to end with ;, not ,.
window.onload = function() {
var dir = 'http://seriousphotography.co.uk/HD-Site/images/album/01/';
var randomCount = Math.round(Math.random() * (imgCount - 1)) + 1;
var images = new Array;
images[1] = "01";
images[2] = "02";
images[3] = "03";
images[4] = "04";
images[5] = "05";
images[6] = "06";
images[7] = "07";
images[8] = "08";
images[9] = "09";
images[10] = "10";
document.getElementById("image").style.backgroundImage = "url(" + dir + images[randomCount] + ".jpg" + ")";
};
It would be simpler to write it as:
window.onload = function() {
var dir = 'http://seriousphotography.co.uk/HD-Site/images/album/01/';
var images = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10"];
var randomCount = Math.floor(Math.random() * images.length);
document.getElementById("image").style.backgroundImage = "url(" + dir + images[randomCount] + ".jpg" + ")";
};
See Get random item from JavaScript array
Using classes and jQuery, it would be:
$("#image").addClass("image"+images[randomCount]);
Fiddle: http://jsfiddle.net/barmar/LgjzvcpL/12/
The multiple abc ids are just filler text for now – Matthew Kelly Oct 25 '14 at 02:37