PDA

View Full Version : Alternate images according to clock



zabooo
07-09-2007, 09:38 PM
I have tried like hell searching on DD to find this but can't.

I need to have 2 different images on a page according to the time of day. I have the code for pictures on 7 days and alternate messages according to TOD but not swapped images. Can anyone help me? It's prbably right under my nose too... Thanks!

Chris

Trinithis
07-09-2007, 10:01 PM
var image = document.getElementById("imgId");

var time = new Date().getHours(); //returns a number from 0 to 23 (inclusive), where 0 local midnight morning.

if(time<12) image.src = "test1.jpg";
else image.src = "test2.jpg";


Feel free to change the if() conditions and you can also add more ifs

For more on the Date object, http://www.w3schools.com/jsref/jsref_obj_date.asp