jQuery .toggle() called by window.setInterval() not functioning
- by Paul Daly
I am trying to alternate between two logos every 5 seconds using the following code:
window.setInterval(
function () {
//breakpoint 1
$("#logo").toggle(
function() {
//breakpoint 2
$(this).attr('src', '/Images/logo1.png');
},
function() {
//breakpoint 3
$(this).attr('src', '/Images/logo2.png');
}
);
},
5000
);
I can get a simple toggle to work, but when I introduce the toggle within window.setInterval(), the toggle's two handlers won't fire.
I set breakpoints on the lines directly beneath the comments in the code above. Breakpoint 1 hits every 5 seconds. However, Breakpoint 2 and 3 never hit.
Why are neither of the toggle function's handlers firing?