I want integreat this JavaScript code to change the background-image depending on current time . the problem is nothing show up if i put the code in a simple html file.
The code is woking live here though: http://jsbin.com/femem/1/edit
here is the code:
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<script src="js/bg.js"></script>
</head>
<body>
<h1>
some text
</h1>
</body>
</html>
code JavaScript:
var d = new Date(),
h = d.getHours(),
i;
if (h < 6) {
i = "http://placehold.it/450x150";
} else if (h < 10) {
i = "http://placehold.it/250x150";
} else if (h < 18) {
i = "http://placehold.it/350x150";
} else if (h < 23) {
i = "bgbody.jpg";
} else {
i = "http://placehold.it/450x150";
}
document.body.style.background = "url(" + i + ")";
Uncaught TypeError: Cannot read property 'style' of null