Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh the src of <img /> with jQuery?

Tags:

jquery

<img src="test.php" /> 

where test.php generates an image with a random number.

Itried :

$('#verifyimage').click(function() {         $(this).attr('src',$(this).attr('src'));     }); 

But it doesn't work.

like image 508
user198729 Avatar asked Jan 04 '10 06:01

user198729


People also ask

How do I refresh IMG?

Reload Images. Reload images in Tab/Window using context menu. This extensions provides a simple way to reload image using context menu. Just right on image and select "reload this image" or right click on page and click "reload all images" in Tab or Window.

How do I refresh an image in HTML?

newImage. src = "http://localhost/image.jpg?" + new Date(). getTime(); This will append the current timestamp automatically when you are creating the image, and it will make the browser look again for the image instead of retrieving the one in the cache.

How can I refresh a page with jQuery?

Method 1: Using the location. reload(): The location. reload() method reloads the current web page emulating the clicking of the refresh button on the browser.

How add src attribute in jQuery?

Answer: Use the jQuery attr() Method You can use the attr() method to change the image source (i.e. the src attribute of the <img> tag) in jQuery. The following example will change the image src when you clicks on the image.


1 Answers

You can force a refresh by appending a random string at the end, thus changing the URL:

$('#verifyimage').click(function() {     $(this).attr('src', $(this).attr('src')+'?'+Math.random()); }); 
like image 194
K Prime Avatar answered Sep 22 '22 18:09

K Prime