Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Replace som text in src url on multiple images

Hiy guys, I’m trying to replace "?d=80×80" with "?d=280×280" from the img src urls in different feeds i have on a page.

I tried this code:

jQuery(document).ready(function( billeder ){
jQuery('.mobile.desktop img').attr('src',jQuery('.mobile.desktop img').attr('src').replace('?d=80x80', '?d=280x280'))
});

But it makes all the images the same image, because it changes all the src url’s to the same url.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Can anyone see what i’m doing wrong?

Can i somehow make the code do it for each image individually?

>Solution :

There might be a way to use .attr with a callback, but for simplicity I used .each:

jQuery(document).ready(function( billeder ){
  jQuery('.mobile.desktop img').each(function () {
    jQuery(this).attr('src', jQuery(this).attr('src').replace('?d=80x80', '?d=280x280'))
  });
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading