1

I am getting an image tag which looks like this

http://sits-pod18.demandware.net/dw/image/v2/aaen_s31/on/demandware.static/Sites-kerastase-Site/Sites-kerastase-master-catalog/default/v1349421867355/large/Styling/Construct/Mousse_Bouffant_1000x1000.png?sw=226&sh=226', sizingMethod='scale'); border:none;" ;="">

If I simplify this then the http strings for the image tags looks like this

http://sits-pod18.demandware.net/dw/image/v2/aaen_s31/on/demandware.static/Sites-kerastase-Site/Sites-kerastase-master-catalog/default/v1349421867355/large/Styling/Construct/Forme_Fatale_1000x1000.png?sw=350&sh=350

http://sits-pod18.demandware.net/dw/image/v2/aaen_s31/on/demandware.static/Sites-kerastase-Site/Sites-kerastase-master-catalog/default/v1349421867355/large/Styling/Construct/Mousse_Bouffant_1000x1000.png?sw=226&sh=226

There are lets say 10 -15 of these tags enclosed in a divs with a class="foo"

I am trying to alter the sw=226&sh=226 to sw=350&sh=350 using jquery.

How should I approach this? Unfortunately I cant alter the way the image is coming in the page. If I could do that then I would approach to alter the height and the width attribute of the image tag.

Let me know if this sounds confusing then I can try to prepare a fiddle to explain it. The tricky part is it has to work in jquery 1.3.2..which is totally nuts

Thanks in advance

Gökay Gürcan
  • 1,082
  • 1
  • 10
  • 25
soum
  • 1,131
  • 3
  • 20
  • 47

2 Answers2

2

Try

$('.foo').each(function() {
    this.src = this.src.replace(/=226/g, '=350');
});
BadgerPriest
  • 723
  • 5
  • 11
  • Hi Badger...I tried your solution too. Couldnt make it work. I have put together a fiddle with T.J s solution here http://jsfiddle.net/sghoush1/djWbd/2/ – soum Jul 23 '13 at 05:36
  • @badger--I see what you did. Nice. But unfortunately I have to make it work on jquery 1.3.2 :-(...pretty sad but I wish I could just change the version – soum Jul 23 '13 at 06:00
  • @soum, this code should work the same in jQuery 1.3.2. `.each()` has been around since jQuery 1.0. Which part of it doesn't work for you? – BadgerPriest Jul 23 '13 at 06:06
  • That was totally my bad. I forgot to add a document ready after removing the 1.9.1..it worked ! thanks again – soum Jul 23 '13 at 06:15
1

This is a simple string replacement:

img.src = img.src.replace("sw=226&sh=226", "sw=350&sh=350");

...where img is the HTMLImageElement in question.

To do a bunch of those with jQuery, you'd use each:

$("selector for the images in question").each(function() {
    this.src = this.src.replace("sw=226&sh=226", "sw=350&sh=350");
});
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • I tried your solution. I think I am missing something here. Here is my fiddle http://jsfiddle.net/sghoush1/djWbd/2/ – soum Jul 23 '13 at 05:34
  • @soum: Yes, your fiddle was missing jQuery: http://jsfiddle.net/djWbd/5/ (there I'm using 1.10, but any version of jQuery is fine for the code above). Other than that, it was fine. – T.J. Crowder Jul 23 '13 at 06:16
  • Yes..just realized that. I think its my bed time and not thinking very streetlight. Thanks again for the solution – soum Jul 23 '13 at 06:20