GibboK GibboK - 2 years ago 121
Javascript Question

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

I need to change the

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

Answer Source

Try like this

$(this).attr("src", urlAbsolute)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download