Hey. There is a picture, it is necessary to remove it on the way to the picture -300x214, despite the fact that if the picture is small, the image does not resize.

<img src="http://example.ru/01/kmg05-300x214.jpg" class="attachment-portfolio-three" alt="kmg05"> 

Thank you in advance.

    2 answers 2

     $(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/

      You can do more universally without jQuery, just in case the size changes:

       var images = document.querySelectorAll('.attachment-portfolio-three'); Array.prototype.forEach.call(images, function(img){ img.src = img.src.replace(/-\d{2,4}x\d{2,4}/, ''); }); 
      • A working joke, just why that last one in the last product of the categories does not change the way the picture. - Roman20