You are using attr()
in a wrong way.
First, attr('src')
will only retrieve the current value, after changing it, you have to use attr('src', newvalue)
to set it.
Second, attr()
will only work on the first element of the collection. If you have more than one elements, you can use an each()
loop on them, or call attr()
with a function that will run for every attribute value, and the returned value will be set as the attribute's new value.
Here is an example for the latter (and a little demo):
$('.class1').find('img').attr('src', function(i, val) {
return val.replace(/\.jpg$/,'-xyz.jpg');
});
This is all explained in detail in the documentation, which I recommend you read.