;

How to Refresh an Image using Javascript or Jquery


Tutorialsrack 30/12/2019 Jquery Javascript

In this article, we will learn how to refresh an image using javascript or jquery.

A few days back, I was facing a problem and the problem was that image URL was changed on button click event in jquery but the image is not refreshed. This  problem happens due to these two reasons:

  1. Your browser caching the image.
  2. The jQuery does not fire or at least doesn't update the attribute

In my case, my browser caching the image and this problem could be solved by forcing the browser to reload the image by passing an extra variable like so:

Code - Here is the code to Refresh the Image using Jquery or Javascript
d = new Date(); 

$("#myimgID").attr("src", "/myimgURL.jpg?"+d.getTime());

I hope this article will help you to understand how to refresh an image using javascript or jquery.

Share your valuable feedback, please post your comment at the bottom of this article. Thank you!


Related Posts



Comments

Recent Posts
Tags