$(document).ready(function() { var img = $('.attachment-portfolio-three'); var source = img.attr('src'); if (source.toLowerCase().indexOf("-300x214") >= 0) { source = source.replace("-300x214", ""); img.attr("src", source); } });
http://jsfiddle.net/8NSST/5/
or even so
$(document).ready(function() { var img = $('.attachment-portfolio-three'); var source = img.attr('src'); var str = "-300x214"; if (source.toLowerCase().indexOf(str) >= 0) { source = source.replace(str, ""); img.attr("src", source); } });
http://jsfiddle.net/8NSST/6/
UPD If you need to remove -300x214
from different images with the same class .attachment-portfolio-three
, then the code is
$(document).ready(function () { var img$ = $('.attachment-portfolio-three'); var str = "-300x214"; img$.each(function () { var source = $(this).attr('src'); if (source.toLowerCase().indexOf(str) >= 0) { source = source.replace(str, ""); $(this).attr("src", source); } }); });
http://jsfiddle.net/8NSST/9/