'Replace som text in src url on multiple images
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?
Solution 1:[1]
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'))
});
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | James |
