jQuery .toggle() called by window.setInterval() not functioning
Posted
by Paul Daly
on Stack Overflow
See other posts from Stack Overflow
or by Paul Daly
Published on 2010-05-12T07:00:40Z
Indexed on
2010/05/12
7:04 UTC
Read the original article
Hit count: 225
jQuery
|JavaScript
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?
© Stack Overflow or respective owner