I have been stuck on this problem for a while now and I need some help trying to figure out how to "refresh" a gif image every time I hit a button. I have tried a ton of the online ideas for this but none of them seem to be working. It only will play the gif once I clear my browser history so I think it may be some caching problem. Can someone spot where I am going wrong or have any tips on how to fix this?
My html:
<div class="logo">
<button class="chains" id="chains" onclick="chains();"></button>
<div id="png">
<img src="images/logo.png" alt=""/>
</div>
<div id="gif">
<img src="images/chains.gif" alt="" />
</div>
</div>
My Javascript function:
<script language="JavaScript">
$( document ).ready(function() {
var myDiv = document.getElementById('gif');
myDiv.style.visibility = "hidden";
});
function chains() {
d = new Date();
$("#gif").attr("src", "images/chains.gif?"+d.getTime());
var logo = document.getElementById("png");
var gif = document.getElementById("gif");
var hide = function(){
logo.style.visibility = "hidden";
gif.style.visibility = "visible";
setTimeout(show, 2300); // 5 seconds
}
var show = function(){
gif.style.visibility = "hidden";
logo.style.visibility = "visible";
}
hide();
};
</script>