Results 1 to 2 of 2

Thread: Alternate images according to clock

  1. #1
    Join Date
    Jul 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Alternate images according to clock

    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

  2. #2
    Join Date
    May 2007
    Location
    USA
    Posts
    373
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    Code:
    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •