I am trying to replace an img path in jquery (injecting into a remote page)
replace example.com/thumbs
with ex
You need to update the attribute with the returned value for that you can use a callback function as the second argument in attr() method where the second argument holds the current attribute value.
$('img').attr('src', function(i, src){
return src.replace('thumbs', 'images');
});
The above method will iterate over the img
tags if there are multiple img
elements so you can avoid using each() method for iterating.
setTimeout(function() {
$('img').attr('src', function(i, src) {
return src.replace('thumbs', 'images');
});
}, 2000);