I have a small custom made thumbnail gallery. On click of a thumbnail I want to get the bigger version of the image. To do this I am getting the img's src. With that I want to replace a certain section of the string for another string. For example the thumbnail's source may look like this:
/media/uploads/headshots/width_60_259850_10150280251835435_717615434_9570015_4084479_n.jpg
I need to replace width_60_ with width_104_. Is this possible with Javascript?
-
@JAAulde, SO should replace Google for such. Otherwise, vote it down, vote to close, provide an answer, a relevant comment... but snotty remarks are not needed.Sparky– Sparky2011年10月14日 15:38:55 +00:00Commented Oct 14, 2011 at 15:38
-
@Sparky672 I voted it down and provided a comment about why...standard SO procedure...JAAulde– JAAulde2011年10月14日 15:39:50 +00:00Commented Oct 14, 2011 at 15:39
1 Answer 1
Simply use the JS replace() function:
var imgSrc = "/media/uploads/headshots/width_60_259850_10150280251835435_717615434_9570015_4084479_n.jpg"
var newSrc = imgSrc.replace("width_60_", "width_104_");
Here's a working jsFiddle.
answered Oct 14, 2011 at 15:23
James Hill
62.2k22 gold badges150 silver badges166 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js