views:

60

answers:

1

HTML:

<div id="coin1"></div>

JS:

 $(document).ready(function(){

   function changeImage(){


if($("#coin1").css("display") == "none"){  
$("#coin1").fadeIn("slow");
}else{  
$("#coin1").fadeOut("slow");
}
};





       setInterval ( "changeImage()", 2000 );
});

I can't get this to work... If I just do changeImage(); it works fine, but I want setInterval to work.. any ideas?

+5  A: 

Because you're defining changeImage() within $(document).ready(), it isn't defined globally and therefore won't be called by setInterval. Use the function's name instead, i.e.:

setInterval(changeImage, 2000);

Hope this helps.

Donald Harvey
that was the trick... I had just figured out that I could put the function outside of (document).ready(function() as well.Thank you!
Jared