LeFizzy LeFizzy - 1 year ago 71
HTML Question

jQuery - Random image generator (fix my code,maybe only syntax errors)

Welcome again,I have some problems with my code.
I still want to get random() background images,but
I can't get it working. It show the default white background with the two text 'title'. :(
My files are => in extension '.jpg' and in directory '/res/images' what's wrong?

<!doctype html>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>


//the highest number of the image you want to load
var upperLimit = 10;

//get random number between 1 and 10
//change upperlimit above to increase or
//decrease range
var randomNum = Math.floor((Math.random() * upperLimit) + 1);

//change the background image to a random jpg
//edit add closing ) to prevent syntax error
$("body").css("background-image","url('res/images/" + randomNum + ".jpg')");//<--changed path

<div id="container1" style="float:left; width:40%; margin:10px;">
<img src="" width='100%' height='100%' />
<div id="container2" style="float:left; width:40%; margin: 10px;">
<img src="" width='100%' height='100%' />

Answer Source

Developer console says:

ReferenceError: $ is not defined.

It means jqery didn't load. Actual reason is missing http:

<script src="http://code.jquery.com/jquery-1.10.2.js"></script>