Check out this jsfiddle:
<img src="https://stackoverflow.com/uploads/lorem_m_1-375x349.png">
<img src="/uploads/ipsum_m_1-248x378.png">
<img src="/uploads/dolor_m_1-392x298.png">
$('img').each(function() {
var src = $(this).attr('src');
$(this).attr('src',replaceNumbers(src));
//console.log($(this).attr('src'));
});
function replaceNumbers(str) {
var regex = /-\d+x\d+/;
return str.replace(regex,'');
}
replaceNumbers() simply takes a string (in this case, your image source) and replaces the ‘-00×00’ with empty string. Then, it returns that string, and in the jQuery each method, each image source is replaced with its changed value.
1
solved Amend img src using jQuery [closed]