Home > front end >  Replace som text in src url on multiple images
Replace som text in src url on multiple images

Time:03-17

Hiy guys, I'm trying to replace "?d=80x80" with "?d=280x280" 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.

Can anyone see what i'm doing wrong?

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

CodePudding user response:

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'))
  });
});
  • Related