-3

I want to change the background color of a page 5 seconds after the initial load. This is my code so far but it's not working:

var startDate = new Date();
var startTime = startDate.getTime();    


var nowDate = new Date();
var nowTime = nowDate.getTime();
var timeDifference = nowTime - startTime;

function difference() {
    if (timeDifference = 5000) {
        $("#body").css("background-color", "red");
    }
}

I would also like to write out the time difference, but it only works with document.write().

Gary
  • 13,303
  • 18
  • 49
  • 71
eyemohini
  • 11
  • 3

1 Answers1

2

Use the setTimeout function:

setTimeout(yourfunction, 5000);

Info: http://www.w3schools.com/js/js_timing.asp

Riad Baghbanli
  • 3,105
  • 1
  • 12
  • 20