Jquery How To Replace Src Url
I have a page that I screen scraped, the scraped page used a relative path for their images and when I load my page, the url of my site is being inserted on the src attr. I need to
Solution 1:
The replace
call returns a new string containing the replacements.
Your code creates a new string that says my_site.com
instead of weather.com
, but doesn't do anything with the string.
You need to write the following:
$(this).attr("src", function(index, old) {
return old.replace('http://my_site.com', 'http://weather.com");
});
Solution 2:
You have typo in 'http://weather.com"
$document.ready(function() {
$("#weather").load("http://weather.com" table:nth-child(3)", function() {
$(this).find("img").each(function() {
var old_site= $(this).attr("src");
var new_site= old_site.replace("http://my_site.com", "http://weather.com");
$(this).attr("src",new_site);
});
});
});
Post a Comment for "Jquery How To Replace Src Url"