Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to efficiently change image attribute "src" from relative URL to absolute using jQuery?

I need to change the src for an html image tag from relative to absolute url.

I am using the following code. urlRelative and urlAbsolute are created correctly but I cannot modify the image in the last line.

What could be wrong wrong in my script?

..... // other code here

     request.done(function(resp) {
            var imgTags = $('img', resp).each(function() {
                var urlRelative = $(this).attr("src");
                var urlAbsolute = self.config.proxy_server + self.config.location_images + urlRelative;
                $(this).attr("src").replace(urlRelative, urlAbsolute); // problem here
            });
like image 972
GibboK Avatar asked Sep 18 '13 08:09

GibboK


3 Answers

Try like this

$(this).attr("src", urlAbsolute)
like image 96
Anil kumar Avatar answered Oct 11 '22 00:10

Anil kumar


Try $(this).attr("src", urlAbsolute);

like image 31
Moeri Avatar answered Oct 10 '22 22:10

Moeri


jQuery("#my_image").attr("src", "first.jpg")
like image 3
manish nautiyal Avatar answered Oct 11 '22 00:10

manish nautiyal