If I just do changeImage(); it works fine, but I can’t figure out how to get setInterval() to work. Here’s my code:
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);
});
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.:Hope this helps.